005-program Startup Process

Source: Internet
Author: User
Master • 1. common files in the project (info. plist And PCH files) • 2. uiapplication • 3. proxy method of appdelegate • 4. complete IOS program Startup Process (relationships between uiapplication, appdelegate, uiwindow, and uiviewcontroller) • 1. Common files in the project (Functions of info. plist And PCH files)
  • Info. plist
1> info. common plist settings • after a project is created, a "project name-info. plist file. This file is very important for some runtime configuration of the project and cannot be deleted. • In the project created in the old version of xcode, the name of this configuration file is "info. plist • Other plist files in the project cannot contain the word "info". Otherwise, it will be considered as a very important "info. plist "• There is an infoplist in the project. strings file, with info. plist file localization related 2> common attributes (the red part is the key that you will see when you open it in a text editor) • localiztion Native Development Region (cfbundledevelopmentregion)-localization related • bundle display name (cfbundledisplayname) -The name displayed after the program is installed. It must be 10-12 characters long. If it is exceeded, the abbreviated name • icon file(cfbundleiconfile0000-app, which is generally icon.png • bundle version (cfbundleversion)-Application version number, each time you release a new version to the App Store, you need to add the version • Main storyboard file base name (nsmainstoryboardfile)-name of the main storyboard file • bundle identifier (cfbundleidentifier) -Unique Project ID, used when deployed to a real machine
  • PCH File
• The project's supporting Files folder contains a "project name-prefix. PCH file, it is also a header file. • The content of the PCH header file can be shared and accessed by all other source files in the project. • generally, some global macros are defined in the PCH file. • Add the following preprocessing commands to the PCH file, then use Log (…) in the project (...) To output the log information, you can remove the nslog statement at one time when publishing the application (in debug mode, debug is defined)

    

#ifdef DEBUG#define Log(...) NSLog(__VA_ARGS__)#else#define Log(...) /* */#endif

 

 

• 2. uiapplication
  • What is uiapplication?
• The uiapplication object is a symbol of an application • each application has its own uiapplication object, in addition, this is a singleton. • This singleton object can be obtained through [uiapplication sharedapplication] • the first object created after an iOS program is started is the uiapplication object • Use the uiapplication object, can perform some application-level operations
  • Common attributes of uiapplication
• Set the red alarm number in the upper-right corner of the application icon

@ Property (nonatomic) nsinteger applicationiconbadgenumber; if the following code is written, the application icon is displayed:

[UIApplication sharedApplication].applicationIconBadgeNumber = 10;  
• Set network indicator visibility

@ Property (nonatomic, Getter = isnetworkactivityindicatorvisible) bool networkactivityindicatorvisible. If the following code is written, the application icon is displayed:

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

 

  • Powerful Openurl method of uiapplication
Uiapplication has a very powerful Openurl: method-(bool) Openurl :( nsurl *) URL; Openurl: some functions of the method include // call uiapplication * APP = [uiapplication sharedapplication]; [App Openurl: [nsurl urlwithstring: @ "Tel: // 10086"]; // send a text message [App Openurl: [nsurl urlwithstring: @ "SMS: // 10086 "]; // send an email to [App Openurl: [nsurl urlwithstring: @" mailto: // [email protected] "]; // open a Web Resource [App Openurl: [nsurl urlwithstring: @ "http://home.cnblogs.com/u/lszwhb/"]; the above method can be used to open other corresponding apps. You do not need to consider what applications you want to open. The system will automatically identify and enable them for you.

 

  • Status Bar in ios7
• From iOS 7, the system provides two methods for managing the status bar. manage through uiviewcontroller (each uiviewcontroller can have its own different status bar) 2. through uiapplication management (the status bar of an application is managed by it in a unified manner)

PS: Before ios7, the status bar is managed by uiapplication. the status bar and uiviewcontroller are independent.

 

• In ios7, the status bar is managed by uiviewcontroller by default. The following methods can be implemented by uiviewcontroller to easily manage the visibility and style of the status bar • the style of the status bar

-(Uistatusbarstyle) preferredstatusbarstyle;

• Status Bar visibility

-(Bool) prefersstatusbarhidden. For example, if you write the following method to uiviewcontroller, the status bar is hidden.

- (BOOL)prefersStatusBarHidden{    return YES;}
• Use uiapplication to manage the status bar. If you want to use uiapplication to manage the status bar, you must first modify the settings of info. plist. • 3. uiapplicationdelegate (proxy method of appdelegate) • all mobile operating systems have a fatal disadvantage: apps are easily disturbed. For example, an incoming call or screen lock may cause the app to enter the background or even be terminated. • there are many other similar situations that may affect the app and some system events may occur when the app is disturbed, at this time, uiapplication will notify its delegate object to let the delegate agent handle these system events • events that delegate can handle include: ø application lifecycle events (such as program startup and shutdown) system events (such as power-on) ø memory warning... ... Ø each time a project is created, there is a class with the word "appdelegate", which is the proxy of the uiapplication.
Ø by default, apappdelegate complies with the uiapplicationdelegate Protocol and is already the proxy of uiapplication. The proxy method of appdelegate is as follows:
/*** After the app is started, it will call */-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {// override point for customization after application launch. return yes;}/*** the app will call */-(void) applicationwillresignactive if it loses focus: (uiapplication *) application {// sent when the application is about to move from active to inactive state. this can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. games shocould use this method to pause the game .} /*** call the app when it enters the background. ** generally, the APP data is stored here (game data, such as suspending the game) */-(void) applicationdidenterbackground :( uiapplication *) application {// use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // if your application supports background execution, this method is called instead of applicationwillterminate: when the user quits .} /*** the app will call the */-(void) applicationwillenterforeground (uiapplication *) when it returns to the foreground from the background *) application {// called as part of the transition from the background to the inactive state; here you can undo changes of the changes made on entering the background .} /*** the app calls the */-(void) applicationdidbecomeactive when getting the focus: (uiapplication *) Application {// restart any tasks that were paused (or not yet started) while the application was inactive. if the application was previusly in the background, optionally refresh the user interface .} /*** memory warning. The program may be terminated to clear unnecessary memory */-(void) applicationdidreceivememorywarning :( uiapplication *) application {}/*** program is about to exit calling */-(void) applicationwillterminate :( uiapplication *) Application {// called when the application is about to terminate. save data if appropriate. see also applicationdidenterbackground :.}
Appdelegate proxy method

 

 

• 4. Complete IOS program Startup Process (relationships between uiapplication, appdelegate, uiwindow, and uiviewcontroller)

Complete process of program startup

1. Main Function

2. uiapplicationmain

* Create a uiapplication object

* Create the delegate object of the uiapplication.

3. The delegate object starts to process (Listen) system events (no storyboard)

* When the program is started, the agent's application: didfinishlaunchingwitexceptions: method will be called.

* Create a uiwindow in application: didfinishlaunchingwitexceptions:

* Create and set the rootviewcontroller of the uiwindow.

* Display window

3. Obtain the file name of the primary storyboard Based on info. plist and load the primary storyboard (with storyboard)

* Create a uiwindow

* Create and set the rootviewcontroller of the uiwindow.

* 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.