簡體   English   中英

iOS-無法讀取文檔目錄中的文件

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

我正在嘗試讀取一個文件,在該文件中我已成功下載並保存在Documents目錄中。 但是,當我嘗試閱讀它時,如果失敗。

這是錯誤:

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"}

這是我的代碼:

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

本地路徑是

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

我嘗試使用NSTemporaryDirectory()和NSFileManager來獲取文件的內容,但是它們均無效。 知道為什么嗎? 提前致謝!

您有權限錯誤。 您沒有打開文件的正確權限。 無論您從何處獲得它,都將被鎖定。 您可以嘗試在模擬器中下載它,並通過Apple的文件系統對其進行檢查,以查看其實際下載了哪些權限。 路徑是:

〜/庫/開發人員/ CoreSimulator /設備//數據/容器/數據/應用程序//文檔。

用顯示今天修改日期的目錄替換兩個大的隨機字符串,或者用NSLog記錄iOS應用程序的真實路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM