12-program startup principle, 12-startup Principle

Source: Internet
Author: User

12-program startup principle, 12-startup Principle
Program startup principles

  • Functions of Info. plist And pch files
  • Common Use of UIApplication
  • Proxy method of AppDelegate
  • Relationships between UIApplication, AppDelegate, UIWindow, and UIViewController
  • Complete iOS program Startup Process
Common settings of Info. plist
  • After a project is created, a file named "project name-Info. plist" is displayed in the Supporting files Folder. This file configures the project during runtime and is very important and cannot be deleted.
  • In the project created in the old version of Xcode, the configuration file name is "Info. plist"

  • Other Plist files in the project cannot contain the word "Info", otherwise it will be mistakenly considered as a very important "Info. plist"

  • The project also contains an InfoPlist. strings file, which is related to the localization of the Info. plist file.

Info. plist
  • Common attributes (the red part is the key that is displayed when opened in a text editor)
  • Localiztion native development region (CFBundleDevelopmentRegion)-localization

  • Bundle display name (CFBundleDisplayName)-the name displayed after the program is installed. It must be 10-12 characters long.

  • Icon file(cfbundleiconfile)-appmap name, which is generally icon.png

  • Bundle version (CFBundleVersion)-the version number of an application. Each time a new version is released to the App Store, the version number must be added.

  • Main storyboard file base name (NSMainStoryboardFile)-name of the Main storyboard file

  • Bundle identifier (CFBundleIdentifier)-Unique identifier of the project, used when deployed to a real machine

Pch File
  • The project's Supporting files folder contains the "Project name-Prefix. pch" file, which 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, and 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

What is UIApplication?
  • The UIApplication object is a symbol of the application.
  • Each application has its own UIApplication object and is a singleton
  • You can use [UIApplication sharedApplication] to obtain the singleton object.
  • The first object created after an iOS program is started is the UIApplication object.
  • Use the UIApplication object to 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;

  • Set network indicator visibility

@ Property (nonatomic, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;

Status Bar in iOS7
  • From iOS 7, the system provides two methods to manage the status bar.
  • 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.

-(UIStatusBarStyle) preferredStatusBarStyle;

-(BOOL) prefersStatusBarHidden;

Use UIApplication to manage the status bar
  • To use UIApplication to manage the status bar, you must first modify the settings of Info. plist.
  • UIApplication has a very powerful openURL: Method

-(BOOL) openURL :( NSURL *) url;

  • OpenURL: some functions of the method include:

UIApplication * app = [UIApplication sharedApplication]; [app openURL: [NSURL URLWithString: @ "tel: // 10086"];

  • Text message

[App openURL: [NSURL URLWithString: @ "sms: // 10086"];

  • Send email

[App openURL: [NSURL URLWithString: @ "mailto: // 12345@qq.com"];

  • Open a webpage Resource

[App openURL: [NSURL URLWithString: @ "http://ios.itcast.cn"];

  • Open other apps
UIApplication and delegate
  • All mobile operating systems have a fatal drawback: 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 will cause app interference. When the app is disturbed, some system events will occur. At this time, UIApplication will notify its delegate object, let the delegate agent handle these System Events
  • Events that can be handled by delegate include:
UIApplication and delegate


IOS program Startup Process

  • The main function executes the UIApplicationMain function.
  • Int UIApplicationMain (int argc, char * argv [], NSString * principalClassName, NSString * delegateClassName );
  • The UIApplicationMain function creates a UIApplication object based on principalClassName, creates a delegate object based on delegateClassName, and assigns the delegate object to the delegate attribute in the UIApplication object.

  • Next, the Main Runloop (event loop) of the application will be created to process the event (the application: didfinishlaunchingwitexceptions: Method of the delegate object will be called after the program is completed)

  • The UIApplicationMain function is returned only when the program Exits normally.

  • UIWindow is a special type of UIView. Generally, only one UIWindow is available in an app.
  • After the iOS program is started, the first view control created is UIWindow, the view of the controller is created, and the view of the controller is added to the UIWindow, the Controller view is displayed on the screen.
  • The reason why an iOS program can be displayed on the screen is that it has a UIWindow
  • That is to say, no UI interface is visible without a UIWindow.
  • There are two common methods to add a UIView to a UIWindow:

  • -(Void) addSubview :( UIView *) view; Add the view directly to the UIWindow, but the UIViewController corresponding to the view is not considered

  • @ Property (nonatomic, retain) UIViewController * rootViewController;

  • Automatically adds the view of rootViewController to UIWindow to manage the lifecycle of rootViewController.

  • Common Methods

  • -(Void) makeKeyWindow;

  • Convert current UIWindow to keyWindow (main window)

  • -(Void) makeKeyAndVisible;

  • Convert the current UIWindow to keyWindow and display it

Obtain the UIWindow
  • [UIApplication sharedApplication]. windows
  • The UIWindow list opened in this application, so that you can access any UIView object in the application (the keyboard popped up by the input text is located in a new UIWindow)
  • [UIApplication sharedApplication]. keyWindow
  • The UIWindow used to receive keyboard and non-touch message events. In the program, only one UIWindow is a keyWindow at a time. If a text box in a UIWindow cannot be entered, it may be because this UIWindow is not a keyWindow.
  • View. window
  • Obtain the UIWindow of a UIView.
Four object relationship Graphs

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.