iOS Core note--ios application startup principle

Source: Internet
Author: User
Tags message queue

1. iOS app launch sample diagram:

2, the application start principle: 2-1, does not start through the storyboard file:
  1. Executes the main function;
  2. Executes the Uiapplicationmain function in the main function, creates the UIApplication object, creates the Applicationdelegate object, and sets it as the proxy for the UIApplication object;
  3. The program starts, turns on the message loop (Main runloop), listens for events and invokes the method of registration, and then invokes the agent's application:didFinishLaunchingWithOptions: methods; In this method, manually create the UIWindow object set to the Proxy window property;
  4. Create the controller and set the controller to the window's root controller (Rootviewcontroller), at which point the view in the controller is automatically loaded onto the window;
  5. Set the created window to be the primary and display (the method that called Window makeKeyAndVisible ).

Sample Program :

1./**
2. 应用程序启动完毕
3. */
4.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
5. // 1. 创建窗口
6. UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
7. self.window = window;
8.
9. // 2. 创建窗口的根控制器
10. UIViewController *vc = [[UIViewController alloc] init];
11. vc.view.backgroundColor = [UIColor redColor];
12. self.window.rootViewController = vc;
13.
14. // 3. 成为主窗口并显示
15. [self.window makeKeyAndVisible];
16.
17. return YES;
18.}
2-2. Start by Storyboard file: Official document Explanation:

  1. Executes the main function;
  2. Executes the Uiapplicationmain function in the main function, creates the UIApplication object, creates the Applicationdelegate object, and sets it as the proxy for the UIApplication object;
  3. Automatically create good UIWindow objects;
  4. Retrieves the most important storyboard (usually the main storyboard) information in the Info.plist file, loads the storyboard file according to the information provided by the Info.plist, and automatically creates a view of the controller and Controller;
  5. Set the created controller to the root controller (rootviewcontroller) of the Window object and display the Windows.
  6. When the application starts, it opens the main Runloop (event loop) of the application, listens for the event and invokes the method of registration (the method that calls the delegate object first after the program is finished application:didFinishLaunchingWithOptions: );
3, Uiapplicationmain () function: Official document explanation: 3-1, uiapplicationmain () parameter instruction:
    1. argc: Use the ARGC in the main function;
    2. argv: Use the argv of the main function;
    3. principalClassName: Specifies the application class name (symbol of the app), which must be uiapplication (or subclass) and, if nil, use the UIApplication class as the default value;

      备注: Incoming Application object class name, nil = = NSStringFromClass([UIApplication class]) = @"UIApplication" .

    4. delegateClassName: Specifies the application's proxy class, uiapplicationdelegate the method defined in the protocol, implemented in the class.
3-2, Uiapplicationmain () function:

    1. Create UIApplication objects based on Principalclassname;
    2. Creates a delegate object based on Delegateclassname and assigns the delegate object to the delegate attribute in the UIApplication object;
    3. UIApplicationMain()function to open a "dead loop" (event loop), so the program does not exit, we can use any. In this "Dead Loop" (event loop) The program constantly listens to the user's various events and processes them sequentially (depending on the "event queue" implementation).

备注: In the message loop to continuously monitor 消息队列 whether there are new events (queue is FIFO, the purpose of the event queue is to improve performance), the message loop can be simply understood as a dead loop, when the system has an event triggered, the method of the event is put into the message queue, the function of the message loop is to keep going to the message There is no new message in the queue, and there is no time for the user to feel the wait.

3-3, Uiapplicationmain () function exit:

备注: The Uiapplicationmain function returns when the program exits normally.

4, program start four object relationship example diagram:

iOS Core note--ios application startup principle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.