The life cycle of an iOS app

Source: Internet
Author: User

The lifecycle of an iOS application, and whether the program is running in the foreground or in the background, transforms the state of the application, which is important to the developer. The resources for iOS systems are limited, and applications are not the same in the foreground and in the background. In the background, the program is subject to many limitations of the system, which can improve battery usage and user experience.

1. Status of the application

Not running running program does not start

Inactive not activated

Active activation

Backgroud Backstage

Suspended hangs

2. Program Status Change chart

  

3. Callback of Agent when program running state

-(BOOL) Application: (UIApplication *) application willfinishlaunchingwithoptions: (nsdictionary *) launchOptions

Tells the agent that the process has started but has not yet entered a state save
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
Tells the agent to start the basic Completion program ready to start running
-(void) Applicationwillresignactive: (uiapplication *) application
When an application is going into an inactive state, during which time the application does not receive messages or events, such as coming to the phone
-(void) Applicationdidbecomeactive: (uiapplication *) application
When the application executes in the active state, this is exactly the opposite of the method above.
-(void) Applicationdidenterbackground: (uiapplication *) application
Called when the program is pushed to the background. So to set the background to continue running, you can set it in this function
-(void) Applicationwillenterforeground: (uiapplication *) application
Called when the program is going back to the foreground from the background, which is exactly the opposite of the method above.
-(void) Applicationwillterminate: (uiapplication *) application
When the program is about to exit is called, it is usually used to save the data and some cleanup work before exiting. This needs to set the key value of the uiapplicationexitsonsuspend.
-(void) applicationdidfinishlaunching: (uiapplication*) application
Executes when the program is loaded

4. Application Life cycle

  

1. Loading the application into the foreground

2. Loading the application into the background

3. About main function

The main function is the entry for program initiation, in the iOS app, the function of the main function is minimized, and its main work is given to the Uikit framework

    1. #import <UIKit/UIKit.h>
    2. int main (int argc, char *argv[])
    3. {
    4. @autoreleasepool {
    5. return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Myappdelegate class]));
    6. }
    7. }

The Uiapplicationmain function has four parameters, you do not need to change these parameter values, but we also need to understand how these parameters and programs start

The ARGC and argv parameters contain the boot time brought over by the system. The third parameter determines the name of the primary application class, which is specified as nil, so that Uikit uses the default program class UIApplication. The fourth parameter is the program's custom proxy class name, which is responsible for the interaction between the system and the code. It is typically generated automatically when Xcode creates a new project.

In addition, the Uiapplicationmain function loads the file of the program's main interface. Although this function loads the interface file, but does not put it on the application's windows, you need to load it in the delegate Application:willfinishlaunchingwithoptions method.

An application can have either a master storyboard file or a master nib file, but not two exist at the same time.

If the program does not automatically load the main storyboard or nib file at startup, you can prepare the Windows display in the Application:willfinishlaunchingwithoptions method.

The life cycle of an iOS app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.