I've got a simple app that's trying to save some data between invocations using NSKeyedArchiver/NSKeyedUnarchiver. It works fine on the simulator, but when I export it to real iPhone hardware, NSKeyedArchiver fails to be able to write to disk.
I'm using the class method
[NSKeyedArchiver archiveRootObject:myRootObject toFile:@"data.archive"]
All my objects in 'myRootObject' implement the NSCoding protocol. Again, on the simulator, this returns YES and everything's good. On the device, this returns NO and nothing has saved. (Both are 2.2.1)
Is there some write permission or something an app needs to be able to write to the phone's HD? Anybody already seen this?
Thanks for your help in advance.
I'm guessing here but wouldn't you specify file path pointing to directory within your bundle? I think you can write to Documents directory under your NSBundle.
Try creating the file path like this:
// Documents directory
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
// <Application Home>/Documents/foo.arch
NSString *fooPath =
[documentsPath stringByAppendingPathComponent:@“foo.arch”];
And then pass "fooPath" as the path to your file in the method you're using, see if that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With