IOS 8 Application Build Detail Mining application startup process

Source: Internet
Author: User
Tags manual garbage collection memory usage uikit

This article follows the authoring common agreement "signed-non-commercial-Consistent"

Reprint please keep this sentence: The beautiful life of the Sun Vulcan-this blog focuses on agile development and mobile and equipment research: IOS, Android, HTML5, Arduino, Pcduino, otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.

24K Title Party!

But the content is absolutely enough detail and comprehensive, only for the START process this small piece of yo!

IOS application start-up process, this topic as early as 09 is very familiar with, but after many years, I do not know whether still familiar with, especially the introduction of StoryBoard, then take a look at it, if it does explain white, give a comment, or where there is insufficient, need to improve, also give a direction.

Since Objective-c is an extension of C, the main function naturally inherits the location of the program's entry, unlike Android, whose program entry point may be main, but it is buried within the framework of the system and may be called a different name, Want to know about the Android startup process.

In XCode 5.1.1 (2014-07-20 Sunday, when IOS 8 has been released, but has not yet been officially put to use, Beta 3 is said to have been available for developers to pay) a new single view application (one application).

There are always many Roriba documents in the XCode project, but that's where it's advanced, where control is concentrated, spread out multiple points for developers to configure to change the operation of the application, perhaps with a fool-like application architecture, but does not open source architecture such as IOS, Will our future generations really become fools, with no understanding of the art of the process within the architecture, and the loss of this architectural capability?

To enter the theme, the program entry MAIN.M file is as follows:

1 2 3 4 5 6 7 8 9 10 #import <uikit uikit.h= "" > #import "AppDelegate.h" int main (int argc, char * argv[]) {@autoreleasepool {     Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]); }} </uikit>

The main function, which is exactly the same as the C language, takes two arguments, ARGC is the number of arguments, argv is an array of arguments, or a list is also OK.

#import in the previous two lines is the same function as the #include macro directive introduced in Objective-c, introducing other header files.

The reason to introduce this new instruction to include the header file is because there is a recurring problem with the #include that a header file is introduced multiple times, and it is possible to define multiple objects or variables.

Therefore, in C, the use of macro directives to determine whether a header file in a predefined macro name exists, do not exist in the macro condition to use #include to introduce the header file, otherwise this macro branch, the header file will not be introduced.

The streamlined structure of the Availability.h header file is as follows, although the header file is introduced in the-prefix.pch file using #import, but it cannot be taken lightly because the file may also be introduced in C code using #include, so the only introduction to C-style is still added Macro structure:

1 2 3 4 5 6 7 #ifndef __availability__ #define __AVAILABILITY__ #include #endif/* __availability__ * * </AVAILABILITYINTERNAL.H&G T

It is a waste of time to deal with this trouble to the right file, so #import came into being without worrying about the problem of duplicate introduction of the header file. However, do not be too happy, circular reference problem, still can't solve, this is to use another @class to declare the existence of the class name in order to define the object reference in the declaration file, and the actual header file is introduced into the implementation file. For the more complicated logic, you have to rely on your overall ability to avoid circular references: that is, a introduces b,b to introduce a.

The most common in IOS applications, which is basically conventional, is to introduce two frameworks: Uikit and Foundation.

In the main.m file, comments out of the introduction of Uikit, the program is also normal operation, because the Uikit is not used, but the program template by default Plus, may be other types of applications will use it, perhaps!

The automatic free pool is not described in depth because the application we are currently creating defaults to support ARC (automatic reference count Automatic Reference counting), so this companion automatic release pool method is used.

@autoreleasepool {

1 }

Earlier ways, already obsolete, this new way, also supports the introduction of the MRC (manual reference count Manual Reference counting) source file, but it is necessary to set the source file compilation part of the corresponding parameter settings, add

1 -fno-objc-arc

On the contrary, in the early MRC project, the method used is outdated, the current XCode will not give you to create such template code, and in the ARC-oriented engineering, that will not be precompiled good processing. If necessary, introduce the source file for arc in the MRC project, and in the compilation options for the Arc source file, enter

 
1 -fobjc-arc

The ARC is simply precompiled, and the compiler adds to the code needed for the appropriate memory management in the MRC that you need to add, rather than the real dynamic memory management, garbage collection, so it's much better in terms of efficiency and memory usage.

Next

1 Uiapplicationmain

becomes the focus, it's equivalent to the WinMain function in MFC.

For a form application, it renders interface elements and responds to user actions, such as mouse, keyboard, touch screen, and other user action events, as well as various sensor events for mobile devices, and so on.

This requires the application with the form, to be able to iterate the query to such events, perhaps the event directly triggered may be faster and save resources, but the consequence is too coupled.

Therefore, the combination of polling and event triggering, appropriate distribution, can achieve the desired effect. Events are distributed by the system to the current application of each or mobile device, which needs to be done by the event cache pool. And each application polling time itself to get the event, or from the outside into the event pool, or from the internal occurrence of this event, and then trigger, and will need to call the callback function to cache, notice, in the application, becomes a cached event callback function, rather than the event itself, the event itself is equivalent to direct delivery. This is a good solution to the low efficiency of polling and high resource consumption and the coupling of direct callback, and so on weaknesses.

The Uiapplicationmain function has four parameters:

1 Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);

The first and second parameters are incoming parameters of the C program body, which are passed in directly without any processing;

The third parameter is the class of the IOS application instance to create, which is uiapplication or its subclasses, each of which applies only one;

The fourth parameter is the application proxy class that you want to create, which can actually be done in the application class, but this proxy pattern is a good way to isolate this part of the functionality from the application class, which is also a great place for Apple to handle various event responses using proxy mode. Developers can only handle the requirements of the Agent method, which is helpful for the uniform specification to anticipate the task, not to confuse the program structure because of the negligence of the developers.

The following is a brief description of the further application initiation process for uiapplicationmain without specifying the proxy class and specifying the proxy class two cases.

There is also the source of the main form, where the application class instance reads the relevant configuration information from the xxx-info.plist.

where Main nib file base name determines whether to get the application window information from nib file or StoryBoard.

1, if it is nib, then the main window is also read from the file, next, you can from the application agent, to the main window to set the root view controller;

If the fourth parameter of Uiapplicationmain applies a proxy class to nil, the application does not know how to find the application proxy class for instantiation, and it will look for it in the main nib file, looking for the following rules:

(This sentence is wrong, not the fourth parameter is empty, just take the application agent from the nib, but specify the main nib, will be found here by default, if not found, then use the four parameters)

A, the main nib file's owner is the current application class, so set to UIApplication or the subclass you specify, and then add an object to the main nib, set it as the application proxy class,

And from the File ' Owner pull line to just joined the set into the application proxy class object, then pop-up options, select Outlets under the delegate, so that the application of the proxy class associated with the application of the proxy reference.

The UIApplication statement in the following UIApplication.h lets you understand how the relationship between the application class and the application proxy class is a combination, and as for the two ways of inheriting and combining the object-oriented reuse mechanism, see Inheritance and Composition:

 
1 2 3 4 5 Ns_class_available_ios (2_0) @interface uiapplication:uiresponder <uiactionsheetdelegate> {@package ID <u Iapplicationdelegate> _delegate; </uiapplicationdelegate></uiactionsheetdelegate>

b, if still can not find, also that is the corresponding application class of the File ' s Owner delegate did not specify the application proxy class, will try to use Uiapplicationmain's fourth parameter application proxy class.

C, if the main nib File ' s Owner does not give the application delegate specified proxy class, and Uiapplicationmain's fourth parameter is also nil, then the application will start, the same as the main window in the nib will be displayed, but there is no proxy class, can not receive the application class Related events for the application life cycle.

2, if it is StoryBoard, the main window is automatically created by the application and the first view controller of the StoryBoard as the root view controller of the main window.

3, if it is empty, then the application regardless of the main window of things, by the developers themselves to fix, at this time running, will be seen in the simulator black screen application, that is, no window, of course, the status bar as part of the window.

So where is the main window created? This involves applying the proxy class, because the window can be dynamically created and specified, and the window can have multiple, but the main window has only one, and only one is visible.

Written one afternoon, edge test, edge confirmation, edge ideas, organizational language and code, there are some actual test process of screenshots confirmed, this follow-up to fill.

Seems to be a shortcoming of what, at that time thought, focus on a certain topic and then go back to look down, found forgotten ...

Come back and think about it and add it anytime.

Of course, this includes the more than 10 20 very good references I've got on the topic, building all of the chrome tags, and I'm really tired today, and it's going to be a long day.

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.