UnauthorizedAccessException:访问路径拒绝Ios

编程入门 行业动态 更新时间:2024-10-27 20:26:19
本文介绍了UnauthorizedAccessException:访问路径拒绝Ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道这已经出现了一些时间,但我无法用我尝试的任何解决方案解决错误。

I know this has come up some time but I am not able to solve the error with any of the solutions I tried.

我刚刚开始测试我的应用程序 - 将屏幕截图保存到ios设备代码是 -

I just started testing my application - to save a screenshot to ios device Code is -

string GetiPhoneDocumentsPath() { string path = Application.dataPath.Substring(0, Application.dataPath.Length - 5); path = path.Substring(0, path.LastIndexOf("/")); return path + "/Documents/"; } string CreateImagesDirectory(string documentsPath) { //System.IO.File.SetAttributes (documentsPath, FileAttributes.Normal); string imagePath = documentsPath +"magicimages/"; if (Directory.Exists(imagePath)) {return imagePath;} DirectoryInfo t = new DirectoryInfo(documentsPath); //Directory.CreateDirectory(imagePath); t.CreateSubdirectory("magicimages"); System.IO.File.SetAttributes (imagePath, FileAttributes.Normal); return imagePath; }

要文件

Debug.Log("Do nothing actually as we need to save to persistent data path"); string documentsPathIphone = GetiPhoneDocumentsPath(); Debug.Log ("document path" + documentsPathIphone); string imagePath = CreateImagesDirectory (documentsPathIphone); //Path = imagePath + fileName; Debug.Log ("path iphone" + Path); Debug.Log("Appllicarion data path -->" + Application.dataPath); //string savepath = Application.dataPath.Replace ("game.app/Data", "/Documents/"); System.IO.File.WriteAllBytes (System.IO.Path.Combine(Path , fileName), screenshot);

假设屏幕截图是字节[]

Assuming screenshot is bytes[]

我得到了例外的主题。我正在使用Unity。

I get the exception that as in subject. I am using Unity.

我得到的错误是 -

Error that I get is -

UnauthorizedAccessException:访问路径/ var / containers / Bundle / Application / 9DA2D489-2037-451E-87D1-FA7354ECD0D1 / Documents被拒绝。

UnauthorizedAccessException: Access to the path "/var/containers/Bundle/Application/9DA2D489-2037-451E-87D1-FA7354ECD0D1/Documents" is denied.

推荐答案

使用保存Application.persistentDataPath 不 Application.dataPath 。请注意,您必须创建一个文件夹并保存在该文件夹中,而不是直接保存到此路径。

You save with Application.persistentDataPath not Application.dataPath. Note that you must create a folder and save inside that folder instead of saving directly to this path.

因此,您保存的最终路径应为:

So the final path you save to should be:

Application.persistentDataPath +Yourfolder / YourFileNale.extension。

Application.persistentDataPath +Documents / YourFileNale.extension。

始终使用 Path.Combine 来组合路径而不是+我在上面使用过。

Always use Path.Combine to Combine paths instead of "+" I used above.

更多推荐

UnauthorizedAccessException:访问路径拒绝Ios

本文发布于:2023-11-08 02:32:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   UnauthorizedAccessException   Ios

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!