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;
    }

猜你喜欢

转载自blog.csdn.net/qiutiange1205/article/details/81214701