All mobile operating systems have a fatal disadvantage: apps are vulnerable to interruptions, such as a call or lock screen that can cause the app to go backstage or even be terminated.
There are a number of other similar situations that can cause the app to be disturbed, causing some system events when the app is disturbed, which UIApplication notifies his delegate object to let delegate objects handle these system events
Common proxy methods
@implementationappdelegate/** * The program is started and will be called*/-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {returnYES;}/** * Call when the program will lose focus*/- (void) Applicationwillresignactive: (UIApplication *) Application {}/** * When the program enters the background, it will be called to save the application data.*/- (void) Applicationdidenterbackground: (UIApplication *) Application {}/** * The program will be called when it enters the foreground*/- (void) Applicationwillenterforeground: (UIApplication *) Application {}/** * When a program receives a memory warning, the call is generally clear that there is no need to use the memory*/- (void) Applicationdidreceivememorywarning: (UIApplication *) application{}/** * Called when activation gets to focus*/- (void) Applicationdidbecomeactive: (UIApplication *) Application {}@end
Delegate: System events that can be handled include:
- Application lifecycle events such as program startup and shutdown
- System events such as incoming calls
- Memory warning
The first object that is created first when the application starts is uiapplication
UIApplication is the symbol of the application when we create a project: The system has automatically created a proxy for me: appdelegate
Application start-up process:
Explore Uiapplicationmainmain function? A uiapplicationmain this function int uiapplicationmain (int argc, char *argv[], nsstring
- Principalclassname, NSString *delegateclassname);? ARGC, argv: Directly to the Uiapplicationmain in line related processing can be
- Principalclassname: Specifies the program class name (symbol of the app), which must be uiapplication (or subclass). If nil, then? Use the UIApplication class as the default value
- Delegateclassname: Specifies the proxy class for the program, which must comply with the Uiapplicationdelegate protocol
- The Uiapplicationmain function creates UIApplication objects based on principalclassname and creates them according to Delegateclassname. A delegate object, and assigns the delegate object to the delegate property in the UIApplication object
- Then it will be built. The program's main Runloop (event loop), the handling of the incoming line event (?). The first thing to do after the program is finished. Using the application:didfinishlaunchingwithoptions of the delegate object:? method)
- The Uiapplicationmain function returns when the program exits normally
UIWindow
- UIWindow is a special kind of uiview that usually has only one uiwindow in an app.
- The first view control created after the iOS program starts is UIWindow, then creates the controller view and finally adds the controller's view to the UIWindow so the controller's view is displayed on the screen.
- An iOS program can be displayed entirely because it has UIWindow
- Which means you can't see any UI without UIWindow.
The complete process of program initiation
1.main function
2.UIApplicationMain
* Create UIApplication objects
* Create a UIApplication delegate object
3.delegate object starts processing (listening) system events (no storyboard)
* When the program is started, the agent's application:didfinishlaunchingwithoptions is called: method
* Create UIWindow in application:didfinishlaunchingwithoptions:
* Create and set UIWindow Rootviewcontroller
* Display window
3. According to Info.plist to obtain the most important storyboard file name, load the main storyboard (with storyboard)
* Create UIWindow
* Create and set UIWindow Rootviewcontroller
* Display window
UIApplication and Delegate agents