I am using开发者_StackOverflow中文版 the following code to call some save methods when my app is either closed or the iphone goes to sleep. I'm just checking they are both OK and correct to use this way?
- (void)applicationWillResignActive:(UIApplication *)application {
[self saveState];
}
- (void)applicationWillTerminate:(UIApplication *)application {
[self saveState];
}
The saveState function simply sets a few NSuserdefaults...
Thanks for any info!
This seems reasonable. You probably don't need the call in -applicationWillResignActive:, as if the user, say, gets a call, -applicationWillResignActive: will be called, but if they TAKE the call, then -applicationWillTerminate: will be called, so you're covered.
This is very normal, provided -saveState is reasonably fast (as in your example). In principle, the call in -applicationWillResignActive:
isn't necessary, but it's a good idea nonetheless.
精彩评论