Develop applications to understand their lifecycle.
Today we touch the life cycle of the iOS app, the iOS portal in the main.m file:
int main (int argc, char * argv[]) { @autoreleasepool { return Uiapplicationmain (argc, argv, Nil, Nsstringfromclas S ([Appdelegate class]));} }
The two parameters of the main function are not available in iOS, including the two parameters for consistency with standard ANSI C. The Uiapplicationmain function, like the first two and main functions, focuses on the last two, the official note is this:
IF Nil is specified for Principalclassname, the value of Nsprincipalclass from the info.plist is used. If there is no//nsprincipalclass key specified, the UIApplication class is used. The delegate class would be instantiated using init. Uikit_extern int uiapplicationmain (int argc, char *argv[], NSString * __nullable principalclassname, NSString * __nullable Delegateclassname);
If the main class (Principal Class) is nil, it will be obtained from the info.plist, if the corresponding key does not exist in Info.plist, then the default is UIApplication, if the proxy class (delegate class) will be created when you create a new project.
According to the Uiapplicationmain function, the program will enter APPDELEGATE.M, which is automatically generated when Xcode creates a new project.
The life cycle of the Application (APPDELEGATE.M):
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {// Override point for customization after application launch. NSLog (@ "ios_didfinishlaunchingwithoptions"); return YES;} -(void) Applicationwillresignactive: (uiapplication *) application {//Sent when the application was about to move from a Ctive 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 (@ "ios_applicationwillresignactive");} -(void) Applicationdidenterbackground: (uiapplication *) application {//Use the method to release shared resources, SA ve user data, invalidate timers, and store enough application state information to restoreR application to the current state of the It is terminated later. If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits. NSLog (@ "Ios_applicationdidenterbackground");} -(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the transition from the back Ground to the inactive state; Here's can undo many of the changes made on entering the background. NSLog (@ "Ios_applicationwillenterforeground");} -(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not yet STA rted) While the application was inactive. If the application is previously in the background, optionally refresh the user interface. NSLog (@ "ios_applicationdidbecomeactive");} -(void) Applicationwillterminate: (uiapplication *) application {//called when the application was about to terminate. S Ave data if appropriate. See also ApplicationdidenterBackground:. NSLog (@ "Ios_applicationwillterminate");}
1. Application Didfinishlaunchingwithoptions: When the application starts, the application starts the portal and executes only once when the application starts. If the user starts directly, the lauchoptions has no data, if started by other means, Lauchoptions contains the content of the corresponding way.
2. Applicationwillresignactive: When the application is going to be switched from active to inactive, the delegate calls to be performed, such as pressing the home button, returning to the home screen, or switching the application between the full screen, etc.
3. Applicationdidenterbackground: The delegate call to execute when the application has entered the daemon.
4, Applicationwillenterforeground: When the application will enter the foreground (is activated), to execute the delegate call, just as the Applicationwillresignactive method corresponds.
5, Applicationdidbecomeactive: After the application has been activated, the delegate call to be executed, just corresponding to the Applicationdidenterbackground method.
6, Applicationwillterminate: When the application is to be fully launched, to execute the delegate call, this need to set the Uiapplicationexitsonsuspend key value.
Initial launch:
2013-05-24 20:20:31.550 Lifeios[451:c07] Ios_didfinishlaunchingwithoptions
2013-05-24 20:20:31.551 Lifeios[451:c07] Ios_applicationdidbecomeactive
Press the home button:
2013-05-24 20:22:17.349 Lifeios[451:c07] Ios_applicationwillresignactive
2013-05-24 20:22:17.350 Lifeios[451:c07] Ios_applicationdidenterbackground
Click on the program icon to enter:
2013-05-24 20:22:56.913 Lifeios[451:c07] Ios_applicationwillenterforeground
2013-05-24 20:22:56.914 Lifeios[451:c07] Ios_applicationdidbecomeactive
The Uiapplicationexitsonsuspend value is not set in the program and the program does not exit completely.
/**
* AUTHOR:JN
* Github:https://github.com/jnkindle
* Cnblogs:http://www.cnblogs.com/jnkindle
* qq:1294405741
*/
IOS app life cycle