简体   繁体   English

iOS-无法读取文档目录中的文件

[英]iOS - Can't Read File Located In Documents Directory

I am trying to read a file in which I successfully downloaded and saved in the Documents directory. 我正在尝试读取一个文件,在该文件中我已成功下载并保存在Documents目录中。 However, when I try to read it, if fails. 但是,当我尝试阅读它时,如果失败。

Here is the error: 这是错误:

2016-03-28 21:00:26.585 App[569:4103] Path is /var/mobile/Applications/3AFA2430-C0DC-44CD-95F8-A89D82B2C348/Documents/combo.bin
2016-03-28 21:00:26.603 App[569:4103] Error in reading Error Domain=NSCocoaErrorDomain Code=257 "The operation couldn’t be completed. (Cocoa error 257.)" UserInfo=0x17df29d0 {NSFilePath=/var/mobile/Applications/3AFA2430-C0DC-44CD-95F8-A89D82B2C348/Documents/combo.bin, NSUnderlyingError=0x17df90b0 "The operation couldn’t be completed. Permission denied"}

Here is my code: 这是我的代码:

    NSError *error;
    NSData *firmwareContentData = [NSData dataWithContentsOfFile:FIRMWARE_LOCAL_PATH options:NSDataReadingMappedIfSafe error:&error];

    NSLog(@"Path is %@", FIRMWARE_LOCAL_PATH);

    if(error)
    {
        NSLog(@"Error in reading %@", error);

        return;
    }

local path is 本地路径是

#define FIRMWARE_LOCAL_PATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"combo.bin"]

I tried using NSTemporaryDirectory(), using NSFileManager to get the contents of the file, but none of them works. 我尝试使用NSTemporaryDirectory()和NSFileManager来获取文件的内容,但是它们均无效。 Any idea why? 知道为什么吗? Thanks in advance! 提前致谢!

You have a permissions error. 您有权限错误。 You don't have the right permissions to open the file. 您没有打开文件的正确权限。 Wherever you got it from, you're locked out. 无论您从何处获得它,都将被锁定。 You might try to download it in the simulator, and check it through Apple's file system to see what permissions it actually downloaded with. 您可以尝试在模拟器中下载它,并通过Apple的文件系统对其进行检查,以查看其实际下载了哪些权限。 The path is: 路径是:

~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//Documents. 〜/库/开发人员/ CoreSimulator /设备//数据/容器/数据/应用程序//文档。

Replace the two big random strings with the directories that show a mod date of today, or NSLog the real path from your iOS app. 用显示今天修改日期的目录替换两个大的随机字符串,或者用NSLog记录iOS应用程序的真实路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM