iPhone: Document dir data does not survive a hard reset
I have just uploaded my app and it was accepted. To my horror, I now discover that if I hold d开发者_如何学Cown the top right button for some time, to turn iPhone off and then repeat that to turn it on again (i.e. a hard reset), the contents of Documents has vanished.
Since the upgrade to 4.x, this is no longer called:
- (void)applicationWillTerminate:(UIApplication *)application {
}
and my data was not being saved any more (but it still "worked" in a qhostly fashion). The fix was to redo my save in this new method:
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
and other changes in this one:
–(void)applicationWillEnterForeground:(UIApplication *)application {
}
After first registering them in viewDidLoad like this:
UIApplication* app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:app];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:app];
精彩评论