Program Start principle
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
Full boot process for iOS programs
...
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, 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
L Common Properties (red is the key you see when opened with a text editor) Ulocaliztion native Development Region (cfbundledevelopmentregion)-Localization related uubundle display Name (Cfbundledisplayname)-After the program is installed, the names displayed are limited to 10-12 characters, and if exceeded, the abbreviated name Uuicon file (cfbundleiconfile)-app icon name is displayed, Typically Icon.pnguubundle version (cfbundleversion)-the application's revision number, which needs to be increased each time a new version is posted to the App Store uumain storyboard file base Name (nsmainstoryboardfile)-Storyboard uubundle identifier (cfbundleidentifier)-The unique identity of the project to use when deploying to a real machine U...L
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
...
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 [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
...
Common Properties of UIApplication
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;
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) ø through UIApplication Management (the status bar of an application is managed by it uniformly)
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
Ø Style of the status bar
-(Uistatusbarstyle) Preferredstatusbarstyle;
Ø Visibility of the status bar-(BOOL) Prefersstatusbarhidden;-...
Using 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 are
Ø Call
UIApplication *app = [UIApplication sharedapplication];
[App Openurl:[nsurl urlwithstring:@ "tel://10086"];
Ø Send SMS
[App Openurl:[nsurl urlwithstring:@ "sms://10086"];
Ø Send mail
[App Openurl:[nsurl urlwithstring:@ "Mailto://[email protected]"];
Ø Open a Web resource
[App Openurl:[nsurl urlwithstring:@ "http://ios.itcast.cn"];
Ø Open Other app o ...
UIApplication and 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 life cycle events (such as program startup and shutdown) Ø system events (such as incoming calls) O Memory warning o ...
UIApplication and delegate
Uiapplicationdelegate
L Each new project, there is a "appdelegate" word of the class, it is the agent of UIApplication
lll
Lnjappdelegate default has complied with the Uiapplicationdelegate protocol, is already the agent of UIApplication L
iOS program start-up process
Uiapplicationmain
A uiapplicationmain function is executed in the main function.
int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname);
ØARGC, argv: Pass directly to Uiapplicationmain for related processing can øøprincipalclassname: Specify the Application class name (symbol of the app), the class must be uiapplication (or subclass). If nil, the UIApplication class is used as the default value Øødelegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol
Uiapplicationmain
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
The application's main Runloop (the event loop) is then 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 returns when the program exits normally
UIWindow
UIWindow is a special kind of uiview that 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.
UIWindow
There are two common ways of adding UIView to UIWindow:
ø-(void) Addsubview: (UIView *) view;
The view is added directly to the UIWindow, but the view corresponding Uiviewcontroller is not ignored
Ø@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
[UIApplication sharedapplication].windows
A list of UIWindow that opens in this app so you can touch any of the UIView objects in your app
(usually input text pop-up keyboard, in a new UIWindow)
[UIApplication Sharedapplication].keywindow
The UIWindow used to receive message events for keyboards and non-touch classes, and only one uiwindow per time in a program is Keywindow. If a text box inside a UIWindow cannot enter text, it may be because this uiwindow is not Keywindow
View.window
Get the UIWindow where a uiview is located
Four object diagrams
Q & A
Life is like toilet paper, when it's okay, try to be less torn. Time is like toilet paper, look at quite a lot, with the use of it is gone ...
Jonathan_lee
How iOS programs start