What method is called when iPhone app is terminated?
I am making a client server application for the iPhone and would like to know which method is called when the iPhone application is terminated. Any help would b开发者_JAVA百科e appreciated.
The method relating to application lifecycle are UIApplicationDelegate
methods. The two you want are:
- (void)applicationWillTerminate:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
If on a multitasking device, applicationDidEnterBackground:
will be called instead of applicationWillTerminate:
. In most cases, you can perform the same code in both callbacks.
- (void)applicationWillTerminate:(UIApplication *)application
in your appdelegate
The method applicationWillTerminate gets called when your application is being shut down. But the applicationDidEnterBackground/applicationWillResignActive methods are (now) infinitely more useful.
-(void)applicationWillTerminate:(UIApplication *)application
in your application delegate will be called. Check this blog post with chart that describes in detail what messages will be sent during launch, termination and when transitioning between background and foreground.
精彩评论