Example code:
#import"AppDelegate.h"@interface appdelegate () @end @implementation appdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.NSLog (@"%@", Nsstringfromselector (_cmd));//_cmd is an iOS built-in parameter to print the current method name directlyreturnYES;}- (void) Applicationwillresignactive: (UIApplication *) Application {//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state. //Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.NSLog (@"%@", Nsstringfromselector (_cmd));}- (void) Applicationdidenterbackground: (UIApplication *) Application {//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits.NSLog (@"%@", Nsstringfromselector (_cmd));}- (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 mad E on entering the background.NSLog (@"%@", Nsstringfromselector (_cmd));}- (void) Applicationdidbecomeactive: (UIApplication *) Application {//Restart Any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.NSLog (@"%@", Nsstringfromselector (_cmd));}- (void) Applicationwillterminate: (UIApplication *) Application {//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.NSLog (@"%@", Nsstringfromselector (_cmd));} @end
1. The first run of the printed message is:
2016-06-30 17:17:19.610 Test Status Change [53450:338456] application:didfinishlaunchingwithoptions:
2016-06-30 17:17:19.613 Test Status Change [53450:338456] applicationdidbecomeactive:
2. When the program switches to the background, the printed message is:
2016-06-30 17:17:24.516 Test Status Change [53450:338456] applicationwillresignactive:
2016-06-30 17:17:25.096 Test Status Change [53450:338456] Applicationdidenterbackground:
3. When the program switches from the background to the foreground, the printed message is:
2016-06-30 17:19:18.335 Test Status Change [53450:338456] Applicationwillenterforeground:
2016-06-30 17:19:18.849 Test Status Change [53450:338456] applicationdidbecomeactive:
4. When the program terminates, it does not execute Applicationwillterminate: This method, but the direct error.
Test app Run status