So my goal is to write out my app's user data to a plist when the app terminates...so I went about implementing this by following an Apple tutorial... I get the feeling that this tutorial is not entirely accurate though, so I'm coming here for help.
http://tuvix.apple.com/library/ios/...rtyLists/QuickStartPlist/QuickStartPlist.html
Basically everything works great in terms of reading in from the plist in the main bundle. No issues there. But when I go to save the plist on termination in the ~/Documents folder...I get problems. Basically it doesn't create the file, and I'm not sure why. I can look in the App's ~/Documents on the simulator and it's not there, and on a device I can't actually look in the folder, but from the behavior I can tell it's not working either.
Here's the code (getWeightDictionary returns my "test" data in dictionary format with the correct keys/values):
Any Ideas? I changed the method from ApplicationShouldTerminate to the entersBackground one...because I can't find any definition that ApplicationShouldTerminate (mentioned in the tutorial) even exists. My guess is it's a Mac OS X method.
http://tuvix.apple.com/library/ios/...rtyLists/QuickStartPlist/QuickStartPlist.html
Basically everything works great in terms of reading in from the plist in the main bundle. No issues there. But when I go to save the plist on termination in the ~/Documents folder...I get problems. Basically it doesn't create the file, and I'm not sure why. I can look in the App's ~/Documents on the simulator and it's not there, and on a device I can't actually look in the folder, but from the behavior I can tell it's not working either.
Here's the code (getWeightDictionary returns my "test" data in dictionary format with the correct keys/values):
Code:
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSString *error;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingFormat:@"Weight.plist"];
NSDictionary *plistDict = [weightDataController getWeightDictionary];
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
if (plistData) {
[plistData writeToFile:plistPath atomically:YES];
}
else {
NSLog(error);
[error release];
}
}
Any Ideas? I changed the method from ApplicationShouldTerminate to the entersBackground one...because I can't find any definition that ApplicationShouldTerminate (mentioned in the tutorial) even exists. My guess is it's a Mac OS X method.