[iOS基礎控制項 - 6.10.6] UIApplicationDelegate

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   color   os   使用   sp   

A.概念1.移動app非常容易受到其他的系統、軟體事件的幹擾,如來電、鎖屏2.app受到幹擾的時候,UIApplication會通知delegate,來代理處理幹擾事件3.delegate可以處理的事件(1)app聲明周期(啟動、關閉)(2)系統事件(來電)(3)緊急事件(記憶體警告) B.使用稱為delegate的條件:遵守UIApplicationDelegate協議項目開始會自動建立:AppDelegate 1.delegate方法
 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2     NSLog(@"app啟動完畢的時候調用"); 3     return YES; 4 } 5  6 - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 7     NSLog(@"app接收到記憶體警告時調用"); 8 } 9 10 - (void)applicationDidEnterBackground:(UIApplication *)application {11     NSLog(@"app進入背景時候調用");12 }13 14 - (void)applicationWillResignActive:(UIApplication *)application {15     NSLog(@"app將要被掛起");16 }17 18 - (void)applicationWillEnterForeground:(UIApplication *)application {19     NSLog(@"app回到前台");20 }21 22 - (void)applicationDidBecomeActive:(UIApplication *)application {23     NSLog(@"app啟用後");24 }25 26 - (void)applicationWillTerminate:(UIApplication *)application {27     NSLog(@"app將要關閉");28 }29  

 

(1)一般的app操作觸發delegate代理監聽事件流程: (2)整個app的啟動過程:  2.main函數中調用的UIApplicationMain函數
1 int main(int argc, char * argv[]) {2     @autoreleasepool {3         return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));4     }5 }
 函數定義:UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName); (1)principalClassName     a.Application類名,必須是UIApplication或者其子類的類名     b.如果是nil,則預設是UIApplication     c.UIApplicationMain函數根據principalClassName建立UIApplication對象 (2)delegateClassName     a.delegate類名,此類必須遵守UIApplicationDelegate協議     b.UIApplicationMain函數根據delegateClassName建立一個delegate,並將其賦值給UIApplication的delegate屬性 (3)進入Main Runloop 事件迴圈,使用delegate對事件進行監聽 (4)程式正常退出,UIApplicationMain函數返回    

[iOS基礎控制項 - 6.10.6] UIApplicationDelegate

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.