The role of Info.plist and PCH files
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, so it cannot be deleted.
In the project created by the older version of Xcode, the profile name is called "Info.plist"
Other plist files in the project cannot have the word "Info", or they will be mistaken for the "info.plist" that is very important in the legend.
There is also a infoplist.strings file in the project that is related to localization of info.plist files
Info.plist
//Common attributes (the red part is the key you see when you open it with a text editor)Localiztion native Development//Localization relatedRegion (cfbundledevelopmentregion)//The program is installed after the name is displayed, limited to 10-12 characters, if exceeded, will be displayed abbreviated nameBundleDisplay name (cfbundledisplayname)//app icon name, typically Icon.pngIcon file (cfbundleiconfile)//Application version number, you need to increase this version number each time you publish a new version to the App StoreBundleversion (cfbundleversion)//The name of the primary storyboard fileMain Storyboard FileBase name (nsmainstoryboardfile)//The unique identity of the project, deployed to the real machine using theBundleidentifier (cfbundleidentifier)
PCH file
The project's supporting files folder has a "project name-prefix.pch" file, which is also a header file
The contents of the 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 in the PCH file, and then use the log (...) in your 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
Common use of 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 [UIApplication Sharedapplication]
The first object created after an iOS program is started is a UIApplication object
Use the UIApplication object to perform some application-level operations
//设置应用程序图标右上角的红色提醒数字@property(nonatomicNSInteger applicationIconBadgeNumber;//设置联网指示器的可见性@property(nonatomicBOOL networkActivityIndicatorVisible;
If you want to use uiapplication to manage the status bar, you first need to modify the Info.plist settings
The status bar in IOS7
Starting with IOS7, the system provides 2 ways to manage the status bar
Through 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, and Uiviewcontroller can easily manage the visibility and style of the status bar by implementing the following methods
//状态栏的样式- (UIStatusBarStyle)preferredStatusBarStyle; //状态栏的可见性- (BOOL)prefersStatusBarHidden;
OpenURL:
uiapplicationThere is a very powerful OpenURL: Method-(BOOL) OpenURL: (Nsurl*) Url;openurl: Some functions of the method are//Calluiapplication*app = [uiapplicationSharedapplication]; [App openurl:[Nsurlurlwithstring:@"tel://10086"]];//Send SMS[App openurl:[Nsurlurlwithstring:@"sms://10086"]];// e-mail[App openurl:[Nsurlurlwithstring:@"Mailto://[email protected]"]];//Open a Web resource[App openurl:[Nsurlurlwithstring:@"http://ios.itcast.cn"]];//Open Other apps
Proxy methods for Appdelegate
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
... ...
The relationship between UIApplication, Appdelegate, UIWindow and Uiviewcontroller
Full boot process for iOS programs
Uiapplicationmain
main函数中执行了一个UIApplicationMain这个函数int UIApplicationMain(intchar *argv[], NSString *principalClassName, NSString *delegateClassName);argc、argv:直接传递给UIApplicationMain进行相关处理即可//principalClassName:指定应用程序类名(app的象征),该类必须是UIApplication(或子类)。如果为nil,则用UIApplication类作为默认值//delegateClassName:指定应用程序的代理类,该类必须遵守UIApplicationDelegate协议UIApplicationMain函数会根据principalClassName创建UIApplication对象,根据delegateClassName创建一个delegate对象,并将该delegate对象赋值给UIApplication对象中的delegate属性接着会建立应用程序的Main Runloop(事件循环),进行事件的处理(首先会在程序完毕后调用delegate对象的application:didFinishLaunchingWithOptions:方法)程序正常退出时UIApplicationMain函数才返回
UIWindow's acquisition
//add UIView to UIWindow in two common ways: -(void ) Addsubview: (uiview *) view; The view is added directly to the uiwindow , but the view corresponds to @property (nonatomic , retain) uiviewcontroller *rootviewcontroller; //automatically adds Rootviewcontroller view to UIWindow, which is responsible for managing the Rootviewcontroller lifecycle common Methods-( Span class= "Hljs-keyword" >void ) Makekeywindow; //make current UIWindow into Keywindow (main window) -(void ) makekeyandvisible; //make the current UIWindow into Keywindow and show
[UIApplication sharedApplication].windows在本应用中打开的UIWindow列表,这样就可以接触应用中的任何一个UIView对象(平时输入文字弹出的键盘,就处在一个新的UIWindow中)[UIApplication sharedApplication].keyWindow用来接收键盘以及非触摸类的消息事件的UIWindow,而且程序中每个时刻只能有一个UIWindow是keyWindow。如果某个UIWindow内部的文本框不能输入文字,可能是因为这个UIWindow不是keyWindowview.window获得某个UIView所在的UIWindow
App Launch principle code example
@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strongnonatomicUIWindow *window;@end
#import "AppDelegate.h" #import "ZLViewController.h" @implementation appdelegate /** * After loading the program will be called */- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) launchoptions{//1. Creating window Self. Window= [[UIWindowAlloc] Initwithframe:[[uiscreen mainscreen] bounds];//2. Setting the background color of a window Self. Window. BackgroundColor= [UicolorPurplecolor];//3. Creating a controllerZlviewcontroller *one =[[zlviewcontroller Alloc]init]; Self. Window. Rootviewcontroller=one;//4. show window to make window Keywindow (main window) \ and Visible[ Self. WindowMakekeyandvisible];//Make Window a Keywindow (main window) //[Self.window Makekeywindow]; return YES;}
Action instances at the application level
/** * Set the red reminder number in the upper right corner of the application icon *@property(nonatomic) Nsinteger applicationiconbadgenumber; * * Set the visibility of the networking indicator * @property(nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible; */#Import "ViewController.h"@interfaceViewcontroller ()-(ibaction) Changeappnum;@end@implementationviewcontroller-(void) viewdidload{[SuperViewdidload];}//Hide and change the status bar by method-(BOOL) prefersstatusbarhidden{returnYES;} -(Uistatusbarstyle) preferredstatusbarstyle{returnUistatusbarstylelightcontent;} -(Ibaction) changeappnum {uiapplication *app=[uiapplication sharedapplication]; [App Setstatusbarhidden:yes Withanimation:uistatusbaranimationfade]; App.statusbarhidden=yes; App.statusbarstyle=uistatusbarstylelightcontent; [App Setstatusbarstyle:uistatusbarstylelightcontent Animated:yes];//0 represents the number in the upper right corner of the iconUiusernotificationsettings *set = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge Categories:nil]; [App Registerusernotificationsettings:set]; App.applicationiconbadgenumber= -;//Set Up Networking statusApp.networkactivityindicatorvisible=yes;/** * URL: A resource's unique path * The composition of the URL = = Protocol header://Host Domain name/path * Composition of network resource URL = = http://www.baidu.com/1.png * Local file The composition of the source URL = = File:///Users/apple/Desktop/1.png * /[App Openurl:[nsurl urlwithstring:@""]];//Call[App Openurl:[nsurl urlwithstring:@""]];//Send SMS[App Openurl:[nsurl urlwithstring:@"sms://10086"]];// e-mail[App Openurl:[nsurl urlwithstring:@"Mailto://[email protected]"]];//Open a Web resource[App Openurl:[nsurl urlwithstring:@"http://ios.itcast.cn"]];}@end
UIApplication life cycle
#Import "AppDelegate.h"@implementationAppdelegate/** * The program is loaded and will be called */-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{NSLog (@"The didfinishlaunchingwithoptions:--program loads and then calls ...");returnYES;}/** * Program loses focus will be called */- (void) Applicationwillresignactive: (uiapplication *) application{NSLog (@"The applicationwillresignactive:--program loses focus will be called ...");}/** * Program enters the background will be called */- (void) Applicationdidenterbackground: (uiapplication *) application{NSLog (@"The applicationdidenterbackground:--program enters the background and calls ...");}/** * Program from the background into the foreground will be called * /- (void) Applicationwillenterforeground: (uiapplication *) application{NSLog (@"The applicationwillenterforeground:--program enters the foreground from the background and calls ...");}/** * Program gets focus will be called */- (void) Applicationdidbecomeactive: (uiapplication *) application{NSLog (@"applicationdidbecomeactive:--program gets focus will call ...");}/** * Program exits will be called */- (void) Applicationwillterminate: (uiapplication *) application{NSLog (@"The applicationwillterminate:--program quits and calls ...");}/** * Program Memory warning will be called */- (void) Applicationdidreceivememorywarning: (uiapplication *) application{NSLog (@"applicationdidreceivememorywarning:--program memory warning will be called ...");}@end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS Development-How the app starts