12.ios Program Start principle

Source: Internet
Author: User

Master


? The role of Info.plist and PCH files ? Common use of UIApplication ? Proxy methods for Appdelegate ? The relationship between UIApplication, Appdelegate, UIWindow and Uiviewcontroller ? The full boot process for iOS programs


Common Files in projects


Info.plist Common Settings


after building a project, you will see a " project name -info.plist" file under the supportingfiles folder, which is very important for the project to do some run-time configuration, so it cannot be deleted.
? In the project created by the older version of Xcode, the name of this configuration file is called "info.plist"The other plist file in the project cannot have the word "Info", or it will be mistaken for the legendary "info.plist" .? There is also a infoplist.strings file in the project that is related to localization of info.plist files

Info.plist


Common Properties (red is the key you see when opened with a text editor)
? Localiztion native developmentregion (cfbundledevelopmentregion)-Localization related
? Bundle Display Name (cfbundledisplayname)-a program that displays the names after installation, limited to 10-12 characters, and if exceeded, will be displayed abbreviated names
? Icon file (cfbundleiconfile)-app icons name, typically icon.png
? Bundle version (cfbundleversion)-The version number of the application, which needs to be increased each time a new version is posted to the App Store
? Main Storyboard file base name (nsmainstoryboardfile)-The name of the primary storyboard
? Bundle identifier (cfbundleidentifier)-Unique identification of the project, deployed to the real machine

PCH file


The project's supporting files folder has a "project name-prefix.pch" file, which is also a header file
the contents of a PCH header file can be shared and accessed by all other source files in the project
? In general, some global macros are defined in the PCH file
? Add the following preprocessing directives to the PCH file, and then use the log (...) in the project. To output the log information, the NSLog statement can be removed at once when the application is published (debug mode is defined)

#ifdef DEBUG

#define LOG (...) NSLog (__va_args__)

#else

#define LOG (...) /**/

#endif


UIApplication


What is uiapplication



? uiapplication objects are symbols of the application
? Each application has its own uiapplication object, and it is a singleton
? This singleton object can be obtained by [uiapplicationsharedapplication]
? The first object created after an iOS program is started is the uiapplication object
? Use uiapplication objects to perform some application-level operations


uiapplication the Common Properties


? Set the red reminder number in the upper right corner of the application icon

@property (nonatomic) Nsinteger Applicationiconbadgenumber;


? Setting the visibility of networking indicators

@property (nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible;




iOS7 the status bar in


? Starting from IOS7, the system provides 2 ways to manage the status barthrough uiviewcontroller management (each Uiviewcontroller can have its own different status bar)managed by UIApplication (the status bar of an application is unified by it)? In IOS7, by default, the status bar is managed by Uiviewcontroller , andUiviewcontroller can easily manage the visibility and style of the status bar by implementing the following methodsstyle of the status bar

-(uistatusbarstyle) Preferredstatusbarstyle;

visibility of the status bar

-(BOOL) Prefersstatusbarhidden;


Use uiapplication to manage the status bar


If you want to use uiapplication to manage the status bar, you first need to modify the Info.plist settings


OpenURL:


? UIApplication has a very powerful OpenURL: Method

-(BOOL) OpenURL: (nsurl*) URL;

-OpenURL: Some of the functions of the method areCall

uiapplication *app= [uiapplicationsharedapplication];

[App OpenURL: [nsurlurlwithstring:@ "tel://10086"];

Send SMS

[App OpenURL: [nsurlurlwithstring:@ "sms://10086"];

send e-mail

[App OpenURL: [nsurlurlwithstring:@ "Mailto://[email protected]"];

open a Web resource

[App OpenURL: [nsurlurlwithstring:@ "http://ios.itcast.cn"];

Open Other app programs


uiapplication and the Delegate


? All mobile operating systems have a fatal disadvantage: apps are vulnerable to interruptions. For example, a call or lock screen will cause the app to go backstage or even be terminated .
There are a number of other similar situations that can cause the app to be disturbed, causing some system events when the app is disturbed, and UIApplication notifies its delegate object, allowing the delegate agent to handle these system events
delegate events that can be handled include:Application lifecycle events (such as program startup and shutdown)system events (such as incoming calls)Memory Warning...



each new project, there is a "appdelegate" word of the class, it is the agent of uiapplication


Mjappdelegate has complied with the uiapplicationdelegate protocol By default and is already a proxy for uiapplication




IOS program Start-Up process




Uiapplicationmain


? The main function executes a uiapplicationmain function?? int Uiapplicationmain (intargc, char*argv[], nsstring*principalclassname,nsstring* Delegateclassname);argc, argv: direct transfer to Uiapplicationmain for related processing can be Principalclassname: Specifies the application class name (symbol of the app), which must be uiapplication(or subclass). If nil, use the uiapplication class as the default value Delegateclassname: Specifies the application's proxy class, which must comply with the uiapplicationdelegate protocol


? The uiapplicationmain function creates a uiapplication object based on Principalclassname and creates a delegate object from Delegateclassname. and assigns the delegate object to the delegate property in the uiapplication object Next, the main Runloop (event loop) of the application is created, and the event is processed (the application:didfinishlaunchingwithoptions of the delegate object is called first after the program is completed: method)  The uiapplicationmain function does not return when the program exits normally

UIWindow


? UIWindow is a special kind of UIViewthat usually has only one UIWindow in an app . after the iOS program starts, the first view control created is UIWindow, then the controller's view is created, the controller's view is added to the UIWindow , and the controller's view is displayed on the screen.  ? An iOS program can be displayed on the screen entirely because it has UIWindow  It says that without UIWindow, you can't see any UI interface .

? There are two common ways to add UIView to uiwindow :-(void) Addsubview: (UIView*) view;

The view is added directly to the UIWindow , but the view's UIis not ignoredViewcontroller

@property(nonatomic,retain)Uiviewcontroller * Rootviewcontroller;

Automatically add Rootviewcontroller view to UIWindow , responsible for managing the Rootviewcontroller lifecycle

? Common methods-(void) Makekeywindow;

Make current UIWindow into Keywindow (main window)

 -(void) makekeyandvisible;

Make the current UIWindow into Keywindow and show it



UIWindow 's acquisition


? [uiapplicationsharedapplication]. Windows

A list of uiwindow Open in this app so you can touch any UIView object in your app

(usually input text pop-up keyboard, is in a new uiwindow )

? [uiapplicationsharedapplication]. Keywindow

The UIWindowused to receive message events for keyboards and non-touch classes , and only one UIWindow per time in a program is Keywindow. If a UIWindow Internal text box cannot enter text, possibly because of this UIWindow is not Keywindow

? view. window

Get the uiwof a UIView indow


Four object diagrams


12.ios program Start principle

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.