Can't Write iPhone Prefrence Lists
I was confounded by an issue writing a plist which worked fine in the iPhone simulator but didn't work on an actual iPhone. The issue was one of permissions. You can't write like this:
NSString *file = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
[dictionary writeToFile:file atomically:YES];
on the iPhone but you can in the simulator. Technically, writing here violates the sandbox paradigm on the iPhone.
However, writing to the temp directory of the sandbox works.
NSString *file = [NSTemporaryDirectory( ) stringByAppendingPathComponent:@"Settings.plist" ];
[dictionary writeToFile:file atomically:YES];
This was somewhat obscured in the Apple documentation because the plist documentation was originally written for OS X programming so it is hard to separate what examples are applicable to the iPhone and what isn't.
Tags
iPhone plistTrackbacks
To send a trackback, use the URL of this story appending ?page=tb at the end.Comments (0)
Leave a Comment
To create links in comments:
[link:http://anders.com/] becomes http://anders.com/
[link:http://anders.com/|Anders.com] becomes Anders.com
Notice there is no rel="nofollow" in these hrefs. Links in comments will carry page rank from this site so only link to things worthy of people's attention.



