IOS 8 Application construction details mining-application startup process

Source: Internet
Author: User

IOS 8 Application construction details mining-application startup process

IOS 8 Application construction details mining-application startup process

Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Sun huoshen's beautiful life-this blog focuses on Agile development and mobile and IOT device research: iOS, Android, Html5, Arduino, pcDuino, otherwise, this blog post is rejected or reprinted. Thank you for your cooperation.


24 K title party!

However, the content is absolutely detailed and comprehensive. It is only for the starting process!


The iOS app startup process is very familiar with this topic as early as years ago. However, after years, I wonder if I am still familiar with it, especially the introduction of StoryBoard. Let's take a look at it, if it is clear, give a comment, or give some advice if there are any deficiencies that need to be improved.


Since Objective-C is an extension of C, the main function naturally inherits the position of the program entry. Unlike Android, although its program entry point may also be main, but it is buried in the root cause of the system framework. It may also be called another name. For details, refer to the Android startup process.


In XCode 5.1.1 (, iOS 8 has been released but has not been officially launched. beta 3 is said to be available for developers) create a Single View Application ).


There are always a lot of files in the XCode project, but this is exactly what it is. Control is centralized and multiple points are distributed for developers to configure and change the Running Effect of applications, it may be more appropriate to use silly application architecture methods. However, whether a non-open-source architecture such as iOS is a long time ago, will our future generations become dummies, I have no idea about the internal program art of the architecture. What if I lose this architecture capability ?!


The main. m file of the program entry is as follows:

#import 
 
  #import "AppDelegate.h"int main(int argc, char * argv[]){    @autoreleasepool {        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));    }}
 
The main function is the same as that in C. It has two parameters. argc indicates the number of parameters, argv indicates the parameter string array, or a list.


In the above two lines, # import is the same as the # include macro instruction introduced in Objective-C, and other header files are introduced.

The reason why we need to introduce this new command to include the header file is that # include has the problem of Repeated introduction, that is, a header file is introduced multiple times, therefore, multiple objects or variables may be defined, which may lead to errors.

Therefore, in C, macro commands are used to determine whether the predefined macro name in a header file exists. If the predefined macro name does not exist, use # include to introduce the header file in macro condition judgment; otherwise, this macro branch is not taken away, header files will not be introduced.

Availability. the simplified structure of the h header file is as follows, although in-Prefix. in the pch file, this header file is imported using # import, but it cannot be ignored because the file may also be imported using # include in the C code, therefore, the unique introduction macro structure of the C style is still added:

#ifndef __AVAILABILITY__#define __AVAILABILITY__#include #endif /* __AVAILABILITY__ */


It is a waste of time to process such a troublesome file, so # import came into being and there is no need to worry about repeated introduction of header files. However, don't be too happy. The problem of circular reference still cannot be solved. This requires another @ class to declare the existence of class names so as to define object references in the Declaration file, the actual header file is introduced into the implementation file. For complicated logic, you still have to rely on your overall ability to grasp the circular reference: A introduces B, B introduces.


IOS applications are the most common and are basically agreed upon. Two frameworks should be introduced: UIKit and Foundation.

In main. in the m file, comment out the introduction of UIKit, and the program will run normally, because UIKit is not used, but the program template is added by default. It may be used by other types of applications, maybe!


The Automatic release pool is not described in detail here, because the applications we have created currently support ARC (Automatic Reference count Automatic Reference Counting) by default, therefore, this method is used to automatically release the pool.

@ Autoreleasepool {

}


The earlier method is outdated. This new method also supports the introduction of MRC (Manual Reference count Manual Reference Counting) source files, but requires parameter settings for the source file Compilation part.

 -fno-objc-arc

On the contrary, in earlier MRC projects, the method used is outdated, and XCode will not create such template code for you, and when it is used for ARC-based projects, that won't be well handled by pre-compilation. If necessary, introduce the source file of the ARC in the MRC project. In the compilation option of the source file of the ARC, enter

 -fobjc-arc

ARC is nothing more than pre-compilation, the compiler adds the corresponding memory management code in the MRC you need as needed, rather than real dynamic memory management, that is, garbage collection, therefore, its efficiency and memory usage are much higher.



Next,

UIApplicationMain
It will become the key content, which is equivalent to the WinMain function in MFC.

For applications with forms, it must present interface elements and respond to user operations, such as mouse, keyboard, touch screen, and other user operation events, as well as various sensor events on mobile devices.

This requires applications with forms to be able to cyclically query such events. Perhaps the direct triggering of the events may speed up and save resources, but the consequence is that the coupling is too strong.

Therefore, the expected effect can be achieved only by combining round robin with event triggering and appropriate allocation. Events are distributed by the system to the current application of each or mobile device. This must be done by the event cache pool, and events generated by each application during polling or placed externally in the event pool, or it occurs internally. After this event is obtained, it is triggered again, and the callback function that needs to be directly called is cached. Note that in the application, it becomes the cache Event Callback Function, rather than the event itself, the event itself is equivalent to direct transmission. As a result, the low efficiency and high resource usage caused by polling are well solved, and the coupling between direct callback and direct callback is tight.


The UIApplicationMain function has four parameters:

UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

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

The third parameter is the class of the iOS app instance to be created. The class is UIApplication or its subclass. Each app only has one class;

The fourth parameter is the application proxy class to be created. The functions of this class can be completed in the application class. However, this proxy mode can well separate these functions from the application class, this is also Apple's skill in handling various event responses in proxy mode. Developers only need to deal with the requirements of the proxy method. It is helpful to unify and standardize the expected work tasks, so as not to confuse the program structure due to developers' negligence.


Next we will briefly describe the process of starting an application in the case that the UIApplicationMain does not specify the proxy class or the specified proxy class.

There is also the source of the main form, the application class instance will read the relevant configuration information from the xxx-Info.plist.

The Main nib file base name determines whether to obtain the application window information from the nib file or StoryBoard,

1. If it is nib, the main window will also be read from the file. Next, you can set the Root View Controller for the main window from the application proxy;

If the fourth parameter of the UIApplicationMain application proxy class is nil, the application does not know how to find the application proxy class for instantiation, and it will be searched in the main nib file. The search rules are as follows:

(This sentence is wrong. If the fourth parameter is not blank, the application proxy is obtained from nib, but the primary nib is specified, it will be found here by default. If it cannot be found, use the fourth parameter)

A. The File's Owner in the main nib File is the current application class, so set it to UIApplication or the subclass you specified, then add an object to the master nib and set it as the application proxy class,

From the File's Owner to the object that is just added to the application proxy class, the option is displayed, select delegate under Outlets, in this way, the application proxy class is associated with the proxy reference of the application class.

The following UIApplication. in h, the UIApplication Declaration allows you to understand that the relationship between the application class and the application proxy class is a combination method. For the inheritance and combination of the two methods of object-oriented reuse mechanism, see inheritance and combination:

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIApplication : UIResponder 
 
  {  @package    id 
  
     _delegate;
  
 
B. If the delegate of the application class corresponding to the File's Owner still cannot be found, that is, the application proxy class is not specified, and the fourth parameter of UIApplicationMain is used as the proxy class.

C. If the File's Owner in the primary nib does not specify the proxy class for the app's delegate, and the fourth parameter of UIApplicationMain is also nil, the app will start as well, and the main window in nib will be displayed as well, however, there is no proxy class, and you cannot receive the application lifecycle events of the application class.

2. For a StoryBoard, the main window is automatically created by the application, and the first view controller of the StoryBoard is used as the Root View Controller of the main window.

3. If it is blank, the application will not care about the main window, but it will be handled by the developer. When running it, the black screen application will be displayed in the simulator, that is, there is no window. Of course, the status bar is part of the window.

Where can I create the main window? This involves the application proxy class, because the window can be dynamically created and specified, and there can be multiple windows, but there is only one main window and only one is visible.


After one afternoon of writing, I tested, confirmed, conceived, and organized the language and code. I still need some confirmation from the actual test process. I will make up for it later.

It seems to be a shortcoming. At that time, I thought about it. I focused on a certain topic and went back to it to look down on it. I found that I forgot ......

Let's talk about it later and try again at any time.

Of course, this also includes 10 to 20 excellent references found on the topics I have discussed here. Let's create a tag group for all Chrome. Today, it's really a little tired, continue this 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.