005-ios App startup process

Source: Internet
Author: User

   Master• 1. Common documents in the project (the role of Info.plist and PCH files)2.uiapplicationproxy methods for 3.appdelegatethe complete start-up process of the 4.ios program (uiapplication, Appdelegate, UIWindow, uiviewcontroller relationships) • 1. Common documents in the project (the role of Info.plist and PCH files)
    • Info.plist
1>info.plist Common Settings• After building a project, you will see a "project name-info.plist" file under the supporting Files folder, which is very important for the project to do some run-time configuration, and it cannot be removed • In the project created by the previous version of Xcode, the name of this profile is called " Info.plist "• Other plist files in the project cannot have the word" Info ", or they will be mistaken for" Info.plist ", which is very important in the legend. There is also a infoplist.strings file in the project that is related to localization of info.plist files2> Common Properties (the red part is the key you see when you open it with a text editor)Localiztion native Development region (cfbundledevelopmentregion)-Localization-related bundle display name (Cfbundledisplayname)-The name of the program is displayed after installation, limited to 10-12 characters, if exceeded, will be displayed abbreviated name icon file (Cfbundleiconfile)-app icon name, typically icon.png bundle version (cfbundleversion)-The version number of the application, each time a new version is posted to the App Store, this version number needs to be added main storyboard file base name (Nsmainstoryboardfile)-The name of the primary storyboard file bundle identifier (Cfbundleidentifier)-Unique identification of the project, deployed to the real machine
    • PCH file
• The supporting files folder under the project has a "project name-prefix.pch" file, and also a header file pch the contents of the header file can be shared and accessed by all other source files in the project • Generally define some global macros in the PCH file • In the PCH text And then use the log (...) in your project to add the following preprocessing directives. 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

·2.uiapplication
    • What is UIApplication
The UIApplication object is the symbol of the application • Each application has its own UIApplication object, and it is a singleton. • This singleton object can be obtained by [uiapplication Sharedapplication] • A The first object created after the iOS program starts is the UIApplication object • Use the UIApplication object to perform some application-level operations
    • Common Properties of UIApplication
• Set the red reminder number in the upper right corner of the application icon

@property (nonatomic) Nsinteger applicationiconbadgenumber; If you write the following code, the app icon displays:

ten;
• Set the visibility of the networking indicator

@property (nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible; If you write the following code, the app icon displays:

[[UIApplication sharedapplication] setnetworkactivityindicatorvisible:yes];

    • The powerful OpenURL method of UIApplication
UIApplication has a very powerful OpenURL: Method-(BOOL) OpenURL: (nsurl*) Url;openurl: Some of the functions of the method are//CallUIApplication *app =[UIApplication sharedapplication]; [App Openurl:[nsurl urlwithstring:@"tel://10086"]];//Send SMS[App Openurl:[nsurl urlwithstring:@"sms://10086"]];//send e-mail[App Openurl:[nsurl urlwithstring:@"Mailto://[email protected]"]];//open a Web resource[App Openurl:[nsurl urlwithstring:@"http://home.cnblogs.com/u/lszwhb/"] ; Use the method above to open the corresponding other app without you thinking about what application to open, the system will automatically recognize to help you open

    • The status bar in IOS7
• Starting from IOS7, the system provides2 KindsHow to manage the status bar1. Through Uiviewcontroller management (each uiviewcontroller can have its own different status bar) 2. Managed by UIApplication (the status bar of an application is unified by it)

PS: before iOS7, the status bar is managed by UIApplication, and the status bar and Uiviewcontroller are separated independently.

• In IOS7,Default ConditionUnderthe status bar is managed by Uiviewcontroller, Uiviewcontroller implements the following methods to easily manage the visibility and style of the status bar • Style of the status bar

-(Uistatusbarstyle) Preferredstatusbarstyle;

    • visibility of the status bar

-(BOOL) Prefersstatusbarhidden; For example, if you write the following method in Uiviewcontroller, the status bar hides the

- (BOOL) prefersstatusbarhidden{    return  YES;
•using uiapplication to manage the status barIf you want to use uiapplication to manage the status bar, you first need to modify the Info.plist settings 3.uiapplicationdelegate (proxy method for appdelegate) • All mobile operating systems have a fatal disadvantage: apps are vulnerable to interruptions. For example, an incoming call or lock screen will cause the app to go backstage or even be terminated. • There are many 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.           Let the delegate agent 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) O Memory warning o ... Ø Each new project, there is a "appdelegate" word of the class, it is the agent of UIApplication
Øapappdelegate default has complied with the Uiapplicationdelegate protocol, is already uiapplication Agent Øappdelegate proxy method is as follows:
/** * When the app is finished, it will be called*/-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{//Override point for customization after application launch.    returnYES;}/** * The app loses focus and is called*/- (void) Applicationwillresignactive: (UIApplication *) application{//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US    Er quits the application and it begins the transition to the background state. //Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}/** * when the app is in the background, call * * Generally save the app's data (game data, such as pause game)*/- (void) Applicationdidenterbackground: (UIApplication *) application{//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in     Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits.}/** * The app program is returned from the background to the foreground will be called*/- (void) Applicationwillenterforeground: (UIApplication *) application{//Called as part of the transition from the background to the inactive state; Here you can undo many of the changes mad E on entering the background.}/** * The app gets focus will call*/- (void) Applicationdidbecomeactive: (UIApplication *) application{//Restart Any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.}/** * Memory warning, may want to terminate the program, clear the memory that does not need to use again*/- (void) Applicationdidreceivememorywarning: (UIApplication *) application{}/** * Program is about to exit the call*/- (void) Applicationwillterminate: (UIApplication *) application{//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.}
Appdelegate Proxy Method

The complete start-up process of the 4.ios program (uiapplication, Appdelegate, UIWindow, uiviewcontroller relationships)

The complete process of program initiation

1.main function

2.UIApplicationMain

* Create UIApplication objects

* Create a UIApplication delegate object

3.delegate object starts processing (listening) system events (no storyboard)

* When the program is started, the agent's application:didfinishlaunchingwithoptions is called: method

* Create UIWindow in application:didfinishlaunchingwithoptions:

* Create and set UIWindow Rootviewcontroller

* Display window

3. According to Info.plist to obtain the most important storyboard file name, load the main storyboard (with storyboard)

* Create UIWindow

* Create and set UIWindow Rootviewcontroller

* Display window

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.