zyl1024 zyl1024 - 6 months ago 16
iOS Question

writeToFile:atomically: does not work on iOS 6.1.3?

I have a plist (

) which I intended can be changed by user data input. Here is what I have done.

NSString *path = (the path for the plist)
NSMutableDictionary *plistFile = [[NSDictionary dictionaryWithContentOfFile:path] mutableCopy];
[plistFile setObject:(an NSString object) forKey:(an NSString key)];
[plistFile writeToFile:path atomically:YES];

So this is what I have coded. It works well on
iPad 3 (new iPad) (iOS 6.1.2)
and my
XCode (4.6) simulator (iOS 6)
. However, it does not work on my
iPad mini (iOS 6.1.3)
. I have found the problem which is in the last step. When I wrote

BOOL success = [plistFile writeToFile:path atomically:YES];

The console always prints 0 which means it does not succeed. But on my iPad 3 and simulator it prints 1, which means success.

That is all I can describe because there is no exception being thrown out or other output. By the way, my iPad 3 (on which it works) is jailbroken but the iPad mini is not. Nevertheless, I use my developer account to codesign on both devices. Can anyone help me? Or else can anyone point to me a new solution?


Try to use

NSError * error = nil;
BOOL success = [plistFile writeToFile:path options:NSDataWritingAtomic error:&error];
NSLog(@"Success = %d, error = %@", success, error);

And then check what error occures. Maybe it can helps you. And you can write only to the document directory. You may have some troubles with your path.