You need to change one of the method signatures in order for the data to persist. Since the introduction of iOS 4, and multitasking, the method
-(void)applicationWillTerminate:(UIApplication *)application
is rarely called since the application does not actually quit, but enters the background. In the AppDelegate method change this method signature to
-(void)applicationWillResignActive:(UIApplication *)application
The full listing would be
Code:
-(void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"Resigning active");
//- (void)applicationWillTerminate:(UIApplication *)application { ////This method is not being called and can be deleted
// Serialize the rootViewController's surveyDataArray
NSData *serializedData;
NSString *error;
serializedData = [NSPropertyListSerialization
dataFromPropertyList:rootViewController.surveyDataArray
format:NSPropertyListXMLFormat_v1_0
errorDescription:&error];
if (serializedData)
{
// Serialization was successful, write the data to the file system
// Get an array of paths.
// (This function is carried over from the desktop)
NSArray *documentDirectoryPath =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *docDir = [NSString stringWithFormat:@"%@/serialized.xml",
[documentDirectoryPath objectAtIndex:0]];
[serializedData writeToFile:docDir atomically:YES];
}
else
{
// An error has occurred, log it
NSLog(@"Error: %@",error);
}
}
Assuming everything else is correct, the data should now be stored, and can be synced in iTunes
Bob