Hang up
When a phone comes in or the screen is locked, your application will hang up. In this case, the UI Application Delegate delegate will be notified to call the application WillResignActive method, which you can rewrite to do the work before hanging up, such as shutting down the network and saving data.
- - (void)applicationWillResignActive:(UIApplication*)application{
- /*Add your own pending code*/
- }
When your program is suspended, it will not run in the background.
Two, recovery
When the program is restored, another delegate method named applicationDidBecomeActive is called, where you can restore your application by saving data before hanging up:
- - (void)applicationDidBecomeActive:(UIApplication*)application{
- /*Add your recovery code*/
- }
Note: The application Did Finish Launching method is also called after the application Did BecomeActive method is invoked when the application is started, so you need to make sure that your code can distinguish recovery from startup and avoid logical bug s.
Three, termination
When the user presses the button or shuts down, the program will be terminated. The application WillTerminate method is called when a program is about to terminate normally. However, if the long main button is forced to exit, this method will not be called. This method should perform the remaining cleanup tasks, such as closing all connections properly and performing any other necessary work before the program exits:
- - (void)applicationWillTerminate:(UIApplication*)application{
- /*Add cleanup code before exit and other work code here*/
- }
Source: http://blog.csdn.net/iukey/article/details/7311115
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // Override point for customization after application launch.
- NSLog(@"\n ===> Program start !");
- return YES;
- }
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- /*
- Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- */
- NSLog(@"\n ===> Temporary procedure !");
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- /*
- Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- */
- NSLog(@"\n ===> Procedures go into the background !");
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- /*
- Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- */
- NSLog(@"\n ===> Procedures enter the front desk !");
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- NSLog(@"\n ===> Program reactivation !");
- /*
- Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- */
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- NSLog(@"\n ===> Procedural contingency provisional !");
- UIDevice *device = [UIDevice currentDevice];
- /*
- Called when the application is about to terminate.
- Save data if appropriate.
- See also applicationDidEnterBackground:.
- */
- }
First operation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (void)applicationDidBecomeActive:(UIApplication *)application
First shutdown (home):
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
Run again:
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
Close again:
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application