iOS程式的啟動過程

來源:互聯網
上載者:User

標籤:輸入   技術   delegate   退出   rom   microsoft   pool   提示   操作   

UIApplicationMain

main函數中執行了一個UIApplicationMain這個函數

int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
argc、argv:直接傳遞給UIApplicationMain進行相關處理即可

principalClassName:指定應用程式類名(app的象徵),該類必須是UIApplication(或子類)。如果為nil,則用UIApplication類作為預設值

delegateClassName:指定應用程式的代理類,該類必須遵守UIApplicationDelegate協議

 

UIApplicationMain函數會根據principalClassName建立UIApplication對象,根據delegateClassName建立一個delegate對象,並將該delegate對象賦值給UIApplication對象中的delegate屬性

接著會建立應用程式的Main Runloop(事件迴圈),進行事件的處理(首先會在程式完畢後調用delegate對象的application:didFinishLaunchingWithOptions:方法)

程式正常退出時UIApplicationMain函數才返回

 

 

程式啟動時執行main函數,在main函數當中有以下操作.
int main(int argc, char * argv[]) {
  @autoreleasepool {
  第三個參數:UIApplication類名或者子類的名稱 nil == @"UIApplication"
  第四個參數:UIApplication的代理的代理名稱
  NSStringFromClass:把類名轉化字串
  NSStringFromClass好處:1.有提示功能 2.避免輸入錯誤
  return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  }
}

程式完整啟動流程
1.執行Main
2.執行UIApplicationMain函數.
3.建立UIApplication對象,並設定UIApplicationMain對象的代理.
UIApplication的第三個參數就是UIApplication的名稱,如果指定為nil,它會預設為UIApplication.
UIApplication的第四個參數為UIApplication的代理.
4.開啟一個主運行迴圈.保證應用程式不退出.
5.載入info.plist.載入設定檔.判斷一下info.plist檔案當中有沒有Main storyboard file base name
裡面有沒有指定storyboard檔案,如果有就去載入info.plist檔案,如果沒有,那麼應用程式載入完畢.

iOS程式的啟動過程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.