Transferred from: http://blog.csdn.net/dwt1220/article/details/29373817
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.
Note: In the project created by the older version of Xcode, this 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 Properties
Localiztion native Development Region (cfbundledevelopmentregion)-Localization related
Bundle Display Name (cfbundledisplayname)-a program that displays the names after installation, limited to 10-12 characters, and if exceeded, will be displayed abbreviated names
Icon file (cfbundleiconfile)-app icons name, typically icon.png
Bundle version (cfbundleversion)-The version number of the application, which needs to be increased each time a new version is posted to the App Store
Main Storyboard file base name (nsmainstoryboardfile)-the name of the primary storyboard
Bundle identifier (cfbundleidentifier)-Unique identification of the project, deployed to the real machine
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
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]
[OBJC]View Plaincopy
- uiapplication *app = [uiapplication SHAREDAPPLICATION];  
- uiapplication *app1 = [uiapplication SHAREDAPPLICATION];  
Li class= "alt" > // uiapplication *app2 = [[ uiapplication alloc] init]; will go wrong.
- nslog (@ "%p - %p ", app, app1); // is the same address
The first object created after an iOS program is started is a UIApplication object
Use the UIApplication object to perform some application-level operations
Such as:
[OBJC]View Plaincopy
- UIApplication *app = [uiapplication sharedapplication];
- App. applicationiconbadgenumber = 998; //Set the number on the application icon
- App. networkactivityindicatorvisible = YES; //Set up Networking animations for the status bar
- //Set the style of the status bar
- //App.statusbarstyle = uistatusbarstylelightcontent; The difference from the following method is that animations cannot be set.
- [App setstatusbarstyle:uistatusbarstylelightcontent animated:YES];
- //Set whether the status bar is hidden
- App. Statusbarhidden = YES; //The difference from the following method is that the animation cannot be set.
- [App Setstatusbarhidden:YES Withanimation:uistatusbaranimationfade];
- Nsurl *url = [Nsurl urlwithstring:@ "http://ios.itcast.cn"];
- [App Openurl:url];
Note: If you want to use uiapplication to manage the status bar in IOS7, you first need to modify the Info.plist settings
In iOS7, the status bar is managed by Uiviewcontroller by default, and Uiviewcontroller can easily manage the visibility and style of the status bar by implementing the following methods
Style of the status bar
[OBJC]View Plaincopy
- -(Uistatusbarstyle) Preferredstatusbarstyle;
Visibility of the status bar
[OBJC]View Plaincopy
- -(BOOL) Prefersstatusbarhidden;
OpenURL
[OBJC]View Plaincopy
- -(BOOL) OpenURL: (nsurl*) URL;
OpenURL: Some of the functions of the method are
Call, send text messages, email, open a web resource
[OBJC]View Plaincopy
- Call
- UIApplication *app = [uiapplication sharedapplication];
- [App Openurl:[nsurl urlwithstring:@ "tel://10086"];
- Texting
- [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://ios.itcast.cn"];
iOS program start-up process
UIApplication and delegate
Delegate events that can be handled include:
Application lifecycle events (such as program startup and shutdown)
System events (such as incoming calls)
Memory warning
A uiapplicationmain function is executed in the main function.
[OBJC]View Plaincopy
- int Uiapplicationmain (int argc, charchar *argv[], nsstring *principalclassname, NSString * Delegateclassname);
ARGC passed in several parameters
argv The value of the passed-in parameter
Principalclassname: Specifies the application class name (symbol of the app), which must be uiapplication (or subclass). If nil, use the UIApplication class as the default value
Delegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol
Appdelegate Method Explanation
[OBJC]View Plaincopy
- Called when the application is finished (automatically called by the system)
- -(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) Launchoptions
- {
- return YES;
- }
- Called when it is about to lose its active state (loses focus, cannot interact)
- -(void) applicationwillresignactive: (uiapplication *) application
- {
- }
- Regain focus (ability to interact with users)
- -(void) applicationdidbecomeactive: (uiapplication *) application
- {
- }
- Called when the application enters the background
- The application's data is typically stored in this method, as well as the state
- -(void) Applicationdidenterbackground: (uiapplication *) application
- {
- }
- Called when the application is about to enter the foreground
- Typically restores the application's data in this method, as well as the state
- -(void) Applicationwillenterforeground: (uiapplication *) application
- {
- }
- This method is called when the application is about to be destroyed
- Note: This method cannot be called if the application is in a suspended state
- -(void) Applicationwillterminate: (uiapplication *) application
- {
- }
- When the application receives a memory warning, it calls the
- It is common to release unwanted memory in this method
- -(void) applicationdidreceivememorywarning: (uiapplication *) application
- {
- }
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.
There are two common ways of adding UIView to UIWindow:
1. Use (void) Addsubview: (UIView *) view; Method
[OBJC]View Plaincopy
- Once the program is started, it is called once, (methods in Appdelegate)
- -(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) Launchoptions
- {
- //Create UIWindow
- self. window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];
- //Create Controller
- //Njviewcontroller *VC = [[Njviewcontroller alloc] init];
- //Add the view of the controller to the UIWindow
- [Self. Window ADDSUBVIEW:VC. view];
- Note: An unknown error will occur, and it is not recommended to use
- //Set the root controller of the UIWindow (recommended using this method) Self.window.rootViewController = VC;
- }
Common methods
[OBJC]View Plaincopy
- An application can have only one main window
- [Self. window makekeyandvisible];
- Let UIWindow become the main window
- [Self.window Makekeywindow];
UIWindow's acquisition
[OBJC]View Plaincopy
- Get the main window of the application
- NSLog (@ "%@", [uiapplication sharedapplication]. Keywindow);
- Get the UIWindow where a uiview is located
- View. Window
Note: 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 the UIWindow is not Keywindow (especially before IOS7)
Four object diagrams
Life cycle Approach
The role of Info.plist and PCH files, uiapplication,ios program startup process, Appdelegate method interpretation, UIWindow, life cycle approach