Application hang, recovery and Termination - IOS development

Keywords: network

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.

  1. - (void)applicationWillResignActive:(UIApplication*)application{    
  2. /*Add your own pending code*/    
  3. }    
 

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:

  1. - (void)applicationDidBecomeActive:(UIApplication*)application{    
  2. /*Add your recovery code*/    
  3. }    
 

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:

  1. - (void)applicationWillTerminate:(UIApplication*)application{    
  2. /*Add cleanup code before exit and other work code here*/    
  3. }    
 

Source: http://blog.csdn.net/iukey/article/details/7311115

 

 

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     // Override point for customization after application launch.  
  4.     NSLog(@"\n ===> Program start !");   
  5.       
  6.     return YES;  
  7. }  
  8.                               
  9. - (void)applicationWillResignActive:(UIApplication *)application  
  10. {  
  11.     /* 
  12.      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. 
  13.      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. 
  14.      */  
  15.     NSLog(@"\n ===> Temporary procedure !");   
  16. }  
  17.   
  18. - (void)applicationDidEnterBackground:(UIApplication *)application  
  19. {  
  20.     /* 
  21.      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.  
  22.      If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
  23.      */  
  24.      NSLog(@"\n ===> Procedures go into the background !");   
  25. }  
  26.   
  27. - (void)applicationWillEnterForeground:(UIApplication *)application  
  28. {  
  29.     /* 
  30.      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. 
  31.      */  
  32.      NSLog(@"\n ===> Procedures enter the front desk !");   
  33. }  
  34.   
  35. - (void)applicationDidBecomeActive:(UIApplication *)application  
  36. {  
  37.     NSLog(@"\n ===> Program reactivation !");   
  38.     /* 
  39.      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. 
  40.      */  
  41. }  
  42.   
  43. - (void)applicationWillTerminate:(UIApplication *)application  
  44. {  
  45.     NSLog(@"\n ===> Procedural contingency provisional !");   
  46.   
  47.     UIDevice *device = [UIDevice currentDevice];  
  48.     /* 
  49.      Called when the application is about to terminate. 
  50.      Save data if appropriate. 
  51.      See also applicationDidEnterBackground:. 
  52.      */  
  53. }  
 

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

Posted by katuki on Sun, 24 Mar 2019 00:57:28 -0700