0

I am trying to read a file in which I successfully downloaded and saved in the Documents directory. 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. Any idea why? Thanks in advance!

3
  • are you sure combo.bin is the file and not a directory? you can make sure using some explore application to analyze your iOS device directory structure (i prefer the app named iExplore) Commented Mar 28, 2016 at 13:12
  • @heximal I am 110% sure combo.bin is a file. It is the firmware we use to upgrade a device. I downloaded it from our server and then I was going to read the file and send it through socket to the device. Commented Mar 28, 2016 at 16:02
  • @heximal Ok, forget what I said earlier. You are right. I mistakenly made combo.bin a directory. I thought I should pass a full path including the file name into the download method. Didn't thought of that. Thank you for pointing that out! :) Commented Mar 28, 2016 at 16:31

1 Answer 1

1

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. The path is:

~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//Documents.

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer. It seems that I made a terrible mistake in passing a path with file name into the download method I called. Still I learned something from you. Thanks again! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.