File operation not working on device
-
15-04-2021 - |
Question
What could make a file operation that is working well on the simulator, to not be working on an iOS device?
When using [NSBundle mainBundle]
, and the file is found by FileManager
, what could be the different reasons for adjacent file operations to have different outcome?
I am noticing this sometimes, and just want to get an idea of what to think about when this happens.
Solution
Seems like you are trying to read a file in your application bundle. You may get its path by code:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"ext"]; //Then you can use NSFileManager to read/copy it
All files in application bundle are readonly. You may get more information from here:
OTHER TIPS
As @Aadhira said in the comment above, the simulator stores its files inside a bunch of folders on your mac, not in some sort of simulated main bundle/docs directory sandbox.
In order to get a static file from your main bundle you must create a path starting from [NSBundle mainBundle]
and add path components onto it.