IOS 8 Application Build Details mining application initiation Process

Source: Internet
Author: User

IOS 8 Application Build Details mining application initiation Process

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.


24K Title Party!

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


IOS app launch process, this topic as early as 09 is very familiar with, but after many years, I do not know whether it is also 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 perfect, also give a pointing.


because Objective-c is an extension of C, the main function naturally inherits the location of the program's entry, not like Android, although its program entry point may also be main, But that is buried within the framework of the root of the system, or may be called other names, want to understand can refer to android system startup procedure Span style= "FONT-SIZE:14PX; font-family:arial; line-height:26px; " >


In XCode 5.1.1 (2014-07-20 Sunday, when IOS 8 was released, but not yet officially available, Beta 3 is said to be ready for developers to be fresh) create a new single-view app in the application.


There are always a lot of Roriba files in the XCode project, but this is what makes it so advanced, that control is concentrated and scattered over multiple points for developers to configure to change the running effect of the application, perhaps more appropriately with a fool-like application architecture, but whether an open-source architecture such as IOS is a long-run Will our future generations really become fools and have no understanding of the procedural art inside the architecture, and lose this architectural ability?!


To cut into the subject, the program entry MAIN.M file is as follows:

#import <UIKit/UIKit.h> #import "AppDelegate.h" int main (int argc, char * argv[]) {    @autoreleasepool {        Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);    }}
The main function, which is exactly the same as in C, takes two arguments, ARGC is the number of arguments, argv is a string array of arguments, or a list is called.


The #import in the above two lines is the new feature introduced in Objective-c and #include macros, introducing other header files.

The reason to introduce this new directive is to include the header file, because #include there is a recurring problem, that is, a header file is introduced multiple times, it is possible to define a number of objects or variables, it will be wrong.

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

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

#ifndef __availability__#define __availability__#include <AvailabilityInternal.h> #endif/* __availability__ */


It's a waste of time to deal with a file that is so troublesome, so #import come into being, without worrying about the problems that the header file introduces repeatedly. However, do not be happy too early, the problem of circular reference, there is no way to solve, this is going to use another @class to declare the existence of the class name to define the object reference in the declaration file, and the actual header file is placed in the implementation file. For the more complex logic, you have to rely on your overall grasp ability to avoid the cyclic reference: a introduced b,b introduced a.


The most common and generally accepted IOS app is the introduction of two frameworks: UIKit and Foundation.

In the main.m file, comment out the introduction of UIKit, the program will run normally, because it is not used UIKit, but the program template by default, it may be other types of application will use it, perhaps!


The automatic release pool, which is not covered here, because the application we are currently creating is supported by the ARC (automatic reference count Automatic Reference counting), so use this companion auto-release pooling method.

@autoreleasepool {

}


The previous approach, which is obsolete, is also supported by the introduction of the MRC (manual reference count Manual Reference counting) source file, except that the source file compilation section needs to be set with the appropriate parameters, plus

-fno-objc-arc

Conversely, in an earlier MRC project, the way it was used was obsolete, and the current XCode would not create such a template code for you, and that would not be well-prepared for the ARC-based project. If you really need to, introduce the arc source file in the MRC project, and in the compilation options of the Arc source file, enter

-fobjc-arc

ARC is nothing more than pre-compilation, the compiler, as needed for you to add the appropriate memory management in the MRC to add the code, rather than the real dynamic memory management, garbage collection, so its efficiency and memory usage is much better.



Next

Uiapplicationmain
will become the focus, it is equivalent to the MFCWinMainFunction.

For applications with forms, 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 on mobile devices.

This requires the application with the form, to be able to iterate over such events, perhaps the direct triggering of events may be faster and save resources, but the consequence is that the coupling is too strong.

Therefore, the combination of polling and event triggering, the appropriate allocation, in order to achieve the desired effect. Events are distributed to the current application of each or mobile device by the system, which needs to be done by the event cache pool, and each application polling period itself gets an event, either by an external placement of the event pool, or by an internal occurrence, after this event is triggered, and the callback function that needs to be called directly is cached, note that in the application, becomes the cache event callback function, not the event itself, which is the equivalent of a direct pass. This is a good solution to the low efficiency of polling and the close coupling of high resource consumption and direct callback, and so on.


The Uiapplicationmain function has four parameters:

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

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

The third parameter is the class of the IOS app instance that you want to create, which is uiapplication or its subclasses, one for each application;

The fourth parameter is the application proxy class to be created, the functionality of which can actually be done in the application class, but this kind of proxy mode can be very good to separate this part of the application class, which is also the Apple uses the proxy mode to handle the various event response of the smart place. As long as the developer has to deal with the requirements of the proxy method, it is helpful to standardize the expected task, and 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 not specifying proxy classes and specifying proxy classes in two cases.

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

where Main nib file base name determines the window information for the app from the nib file or StoryBoard,

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

If the fourth parameter of Uiapplicationmain applies the proxy class to nil, the application does not know how to find the application proxy class to instantiate, it will look in this main nib file, looking for the rule is:

(This is wrong, not the fourth argument is empty, only from the nib to take the application agent, but the main nib is specified, it will be found here by default, if not found, then use the four)

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

And from the File's Owner pull line to the newly added object set to the application proxy class, this will pop up the option, select Outlets under the delegate, so that the application proxy class is associated to the application class proxy reference.

The UIApplication declaration in the following UIApplication.h allows you to understand that the relationship between the application class and the application proxy class is a combination, as in the case of two ways of inheriting and combining the object-oriented reuse mechanism, see Inheritance and Composition:

Ns_class_available_ios (2_0) @interface uiapplication:uiresponder <uiactionsheetdelegate>{  @package    ID <UIApplicationDelegate>  _delegate;
b, if it is still not found, that is, the File's Owner of the corresponding application class delegate does not specify the application proxy class, will be tried to use the fourth parameter of Uiapplicationmain applies a proxy class.

C, if the main nib in the File ' s owner does not specify the proxy class for the application's delegate, and the fourth parameter of Uiapplicationmain is nil, then the application will start, the main window in the nib will be displayed, but there is no proxy class, cannot receive Related events to the application lifecycle of the application class.

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

3, if it is empty, then the application regardless of the main window of the matter, by the developer to fix, at this time run, will see in the simulator Black screen application, that is, no window, of course, the status bar as part of the window.

So where does the main window be created from? 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 is only one, and only one is visible.


Write an afternoon, side test, side confirm, side idea, organization language and code, still lack some actual test process confirmation, this follow up again.

Seems to be the shortcomings of what, at that time thought, focus on a topic and then return to the top to look down, found that forget ...

Go back and think about it and add it at any moment.

Of course, this also includes, I found the topic of the more than 10 20 very good reference, first build all the chrome tag group, today really a little tired, the day to continue.





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.