A. Concept1. Mobile app is very susceptible to other system, software event interference, such as call, lock screen 2.app is disturbed, UIApplication will notify delegate, to Agent processing interference event 3.delegate can handle events (1) App Declaration cycle (start , close) (2) system events (incoming calls) (3) Emergency (Memory warning)
B. UseConditions called delegate: compliance with the Uiapplicationdelegate Protocol project will be created automatically: Appdelegate 1.delegate method
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2NSLog (@"called when the app is up and ready");3 returnYES;4 }5 6- (void) Applicationdidreceivememorywarning: (UIApplication *) Application {7NSLog (@"called when the app receives a memory warning");8 }9 Ten- (void) Applicationdidenterbackground: (UIApplication *) Application { OneNSLog (@"called when the app enters the background"); A } - -- (void) Applicationwillresignactive: (UIApplication *) Application { theNSLog (@"app will be suspended"); - } - -- (void) Applicationwillenterforeground: (UIApplication *) Application { +NSLog (@"app back to front desk"); - } + A- (void) Applicationdidbecomeactive: (UIApplication *) Application { atNSLog (@"after the app is activated"); - } - -- (void) Applicationwillterminate: (UIApplication *) Application { -NSLog (@"app will close"); - } in
(1) The General app operation triggers the delegate agent to monitor the event flow: (2) The entire app startup process: The Uiapplicationmain function called in the 2.main function
1 int Main ( int argc, char * argv[]) { 2 @autoreleasepool { 3 return Uiapplicationmain (argc, argv, Nil, nsstringfromclass ([Appdel Egate class 4 5 }
function definition: Uikit_extern int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString * Delegateclassname); (1) Principalclassname A.application class name, must be the class name of UIApplication or its subclasses B. If nil, the default is uiapplication C.uiapplicationmain letter The principalclassname creates a UIApplication object (2) Delegateclassname A.delegate class name based on the Uiapplicationdelegate protocol B.UIApplic The Ationmain function creates a delegate based on Delegateclassname and assigns it to the delegate attribute of UIApplication (3) into the main Runloop event loop, Use delegate to listen for events (4) The program exits normally, and the Uiapplicationmain function returns
[iOS base Control-6.10.6] Uiapplicationdelegate