iOS的app啓動流程原理

APP的啓動流程

  1. main文件
    #import <UIKit/UIKit.h>
    #import "AppDelegate.h"
    
    int main(int argc, char * argv[]) {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    }

    這個方法會創建:application對象, application代理, 時間循環
    官方描述:

    Creates the application object and the application delegate and sets up the event cycle.
    This function instantiates the application object from the principal class and instantiates the delegate (if any) from the given class and sets the delegate for the application.
    It also sets up the main event loop, including the application’s run loop, and begins processing events. 
    If the application’s Info.plist file specifies a main nib file to be loaded, by including the NSMainNibFile key and a valid nib file name for the value, this function loads that nib file. 

    main函數的return即使有返回值, 它也不會執行
    Even though an integer return type is specified, this function never returns. When users exits an iOS app by pressing the Home button, the application moves to the background.

  2. 讀取info.plist
    如果在info.plist設置了一個main nib將會被加載
     
  3. 加載控制器視圖
    在AppDelegate文件中執行代理函數
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        return YES;
    }

     

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章