ios - 未授权访问异常 : Access to the path is denies Ios

标签 ios unity3d vuforia access-denied

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

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

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);

假设截图是字节[]

我得到了主题中的异常。我正在使用 Unity。

我得到的错误是 -

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

最佳答案

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

所以你保存到的最终路径应该是:

Application.persistentDataPath+"Yourfolder/YourFileNale.extension".

Application.persistentDataPath+"Documents/YourFileNale.extension".

始终使用 Path.Combine 来组合路径,而不是我上面使用的 "+"

关于ios - 未授权访问异常 : Access to the path is denies Ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45130401/

相关文章:

android - 如何解决 "Could not find method bundle() for arguments [build_6plat21h.....] on object of type com.android.build.gradle.LibraryExtension"?

unity3d - 如何在 Unity 脚本中实现 Thread.Sleep() 功能?

iphone - 什么时候写“NSString * str”或“NSString str”?

c# - 如何根据面向旋转的对象更改数组中航路点的顺序?

android - 在 Android 中构建时,Unity3D 文本不显示

android - 我想在 android 的 vuforia 增强现实中更改 3d 模型

Android 应用程序在手机 7.0 上运行良好,但在运行 7.1.2 的平板电脑上加载时崩溃

ios - 应用程序在后台时深层链接不起作用?

iphone - 在 iPhone 中将句子的每个单词的第一个字母转换为大写

ios - 更改标签栏的背景颜色