Step-by-step analysis of the new app launch process

Source: Internet
Author: User
Tags uikit

iOS to know new (i) step-by-step analysis of the new app launch process I contact iOS about half a year, can be said to develop the app, but there are a lot of shortcomings, so I intend to write some technical articles, can reach the new effect of temperature, will inevitably have errors or omissions, but also hope that you crossing feel free. In addition to promote the newly established group of "iOS rookie to Master Road", 312747764, Welcome to share the people who want to join the exchange.

1. Simple description of iOS system
iOS and Mac OS X as well as Android belong to the class Uinx system, but people familiar with Unix-like systems may be disappointed that the personal development of the app will enter a state like chroot, isolated by the operating system, which is called a sandbox, unable to know other applications, and cannot access the file system , cannot use the hardware directly--you can request access through the framework provided by iOS, and Mmap is also modified at the bottom to prevent direct write memory page operations. If you want to develop under iOS, use the framework provided by iOS honestly.


2. Create a new app
Environment: Xcode6
Use Xcode to build a new project, choose the default single View application, and then name a new app that is born, can run directly in the simulator, if there is a developer account, can also be configured to directly connect the machine, The general signature of the new machine, click Fix Issue, Xcode will take care of the rest of the matter, here is not elaborate.


3, the beginning of the app
Despite the creation of an app, we know nothing about its execution, let's first find its entrance, support FILES/MAIN.M
?
1         return uiapplicationmain (argc, argv, nil , &NBSP, nsstringfromclass ([Appdelegate Code class= "OBJC keyword" >class ])

As we all know, the main function is the entrance to the C language program, and it is also the entrance to Objective C.
From an intuitive point of view, if the Uiapplicationmain returns, the program ends, so it returns at the end or never returns, while the incoming controllable parameter is the last parameter, which is the name of a class.
In fact, the Uiapplicationmain function never returns, it is responsible for initializing the class required for the execution of the program, and bringing the program into the event waiting loop, while the last parameter indicates the proxy class required for the program to execute.


4, Appdelegate
Let's first find the file appdelegate.m
In addition to modifying the class of the proxy protocol, main.m almost nothing to change the place, Appdelegate is the developer of the place, almost all of the control of the program starts here, the initialization of the program, the state changes need to be answered here.
You may be confused about the new program, although you can see (void) applicationwillresignactive This kind of state switching function, obviously what code is not, how the interface is displayed?


5, UIWindow
In order to understand the problem of the interface display, first know that iOS is displayed, need a UIWindow class, to manage and locate various views.
To test, we add the following code
?
123 ( bool nsdictionary *) launchoptions {      nslog ("window is%@", self .window) }

After execution, the display
Window is <UIWindow:0x7f9a29532380; frame = (0 0; 375 667); hidden = YES; Gesturerecognizers = <NSArray:0x7f9a2952dab0>; Layer = <UIWindowLayer:0x7f9a2952f490>>
Already has the value, can infer, UIWindow in Uiapplicationmain inside has already established, then the question comes, how does it establish?


6, Storyboard
In the existing file, the biggest suspect is it, Main.storyboard, click on it we can be very intuitive to find that it is in control display. Storyboard is IOS5 after the introduction of the artboard function, can be more convenient to achieve the scene of the transformation and layout of the interface, is a convenient function, relative, a little bit unfavorable to the program itself understanding.
However, we did not understand how uiapplicationmain loaded storyboard.


7, Info.plist
Lock the last suspect, that's it. Info.plist can be seen as a configuration file that is a must-have file in the iOS bundle concept and can be viewed through the man plist, which can be seen directly as a dictionary in the iOS app.
In Info.plist, you can find:
"Main Storyboard file base name" String "main"
Here we change "Main" to "xx", try it.
Program execution crashes, but don't panic, look at the results
?
12 &NBSP;&NBSP;&NBSP;&NBSP; 3   uikit                                 0x0000000101170059-[uiapplication _ Loadmainstoryboardfilenamed:bundle:] + &NBSP;&NBSP;&NBSP;&NBSP; 4   uikit                                0X000000010116F0CB-[uiapplication _runwithmainscene:transitioncontext:completion:] + 1074

proves that it was uiapplication that had previously loaded the storyboard
Delete this entry, then start, the screen becomes a black screen
Log shows window is (null)


8. Manually add window
?
12345678 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //全屏window    self.window.backgroundColor = [UIColor whiteColor]; //白色背景    [self.window makeKeyAndVisible]; //     return YES;}

Start, white screen, success


9. Summary
Although it is a waste of effort, it is easier to figure it out, the app enters by Uiapplicationmain, initializes according to the information in the Info.plist (if there is a storyboard load), and then executes (BOOL) application: ( UIApplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions content, after the completion of the interface drawing, finally started, Enter the event waiting loop.

Step-by-step analysis of the new app launch process

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.