Info. plist, pch, and four objects (UIApplication, UIApplicationDelegate, UIWindow, UIViewController), uiviewcontroller

Source: Internet
Author: User
Tags exit in file info

Info. plist, pch, and four objects (UIApplication, UIApplicationDelegate, UIWindow, UIViewController), uiviewcontroller

Contents
  • 1. Program configuration file info. plist, global header file pch
  • 2. Application Object UIApplication Introduction
  • 3. UIApplicationDelegate introduction, program Startup Process
  • 4. UIWindow object
  • 5. process displayed on the Program Interface
  • 6. Summarize the complete process of program startup
-1. Program configuration file info. plist, global header file pch1. program configuration file info. plist, global header file pch back to the top

In the project configuration, the content in the Info option is actually a copy of the content in the info. plist file, and the info. plist file contains a lot of configuration information about the project startup parameters. Note: If you want to add a custom plist file to the project, the file name should not contain info. Info. plist is modified in the same way as other plist files, and is a key-value pair. Note that when the Source Code method is used to open the file, the key name and plist method are different. As discussed in the xml source code file, the key names are divided into the following types:

Core Foundation Keys
The keys of this class are prefixed with CF to represent the Core Foundation and describe some common behavior items.
Lanch Services Keys
Load service items, provide the configuration on which the App is loaded, and describe how the app starts.
Cocoa Keys
The Cocoa or Cocoa Touch framework depends on these keys to identify more advanced configuration items, such as the main
Nib file, main class. These key descriptions affect how the Cocoa and Cocoa Touch frameworks initialize and run apps.
UIKit Keys
Describes IOS Apps. Every IOS app depends on Info.
Plist keys to communicate with IOS systems. Xcode provides the plist file generated to provide the critical keys required by all apps. However, the app may need to expand the default plist to describe more information, such as customizing the default rotation direction after the app starts, and identifying whether the app supports file sharing.
OS X Keys
Describes the behavior of Mac Apps.

Below are some common key meanings:

1.Localiztion native development region --- CFBundleDevelopmentRegionLocalization is related. If the user's location does not have the corresponding language resources, use the value of this key as the default
2.Bundle display name --- CFBundleDisplayNameSet the name displayed after the program is installed. The program name should be limited to 10-12 characters. If the program name is exceeded, the abbreviated name will be displayed.
3.Executaule dile -- CFBundleExecutableName of the program installation package
4.Bundle identidier --- CFBundleIdentidier The unique identifier string of the bundle. The format of this string is similar to that of com. yourcompany. yourapp: this field is useless if you want your supervisor to run your application using a simulator. If you need to deploy your token on the device, you must generate a certificate, when the supervisor generates the certificate, the corresponding app IDs must be added to the apple website. this token has a Bundle identidier field. If this Bundle identidier is a complete string, the field in the file must be exactly the same as the latter. If the field in app IDs contains a wildcard *, the strings in the file must conform to the description of the latter.
5.InfoDictionary version --- CFBundleInfoDictionaryVersion Info.plistFormat version information
6.Bundle name --- CFBundleNameProduct Name
7.Bundle OS Type code -- CFBundlePackageTypeThe four-letter code used to identify the bundle type
8.Bundle versions string, short --- CFBundleShortVersionStringThe version string of the bundle from the consumer to the user market
9.Bundle creator OS Type code --- CFBundleSignatureCode that identifies the creator with four letters long
10.Bundle version --- CFBundleVersionThe version number of the program to be renewed. This number will be added each time a new version of the application is deployed on the app store.
11.Application require iPhone environment -- LSRequiresIPhoneOSIndicates whether the package can only run on the iPhone OS. Xcode automatically adds this key and sets its value to true. You should not change the value of this key.
12.Main storybard dile base name -- UIMainStoryboardFileThis is a string that specifies the name of the application master nib file.
13.supported interface orientations -- UISupportedInterfaceOrientationsThe device direction supported by the program by default.

The pch file is the prefix header file. Is the global header file after the program runs. After the file is added, you can directly use the various content in the file without using # include or # import in other files, for example, macro definition and constants and some common classes. You can directly use the pch file in xcode5 or before. After xcode6, you must use the Prefix Header entry in the Apple LLVM 6.0-Language entry in Build Settings, set the directory where the pch file is located to $ (SRCROOT)/corresponding folder name/PrefixHeader. pch. For example, you can directly set $ (SRCROOT)/PrefixHeader in the root directory. pch

When there are too many nslogs in the program, it will cause a lot of performance problems (NSLog is an IO operation), it is very bad for the release program, if you find all nslogs in the program in sequence and delete or annotate them, the project items are huge, so you can set a Conditional compilation in pch, if the NSLog is in the debugging status as normal code, if it is in the released status, ignore them.

 

#ifdef DEBUG#define NSLog(...); NSLog(__VA_ARGS__);#else#define NSLog(...);#endif

In the debugging status, the content of _ VA_ARGS _ is replaced... content in (this is a common method used to extract method parameters in macro definition), while NSLog (...) is directly ignored during release (...)

During ios development, it is inevitable that some oc and c Mixed compiling will occur. When a pch file is used, the c file will not recognize the preceding Conditional compilation and # import commands, in this case, another condition compilation should be used to avoid problems:

#ifdef __OBJC__    #import <UIKit/UIKit.h>    #import <Foundation/Foundation.h>#endif
-2. Application Object UIApplication Introduction 2. Application Object UIApplication introduction back to the top

UIApplication is a singleton class that can perform application-level operations.
1. Number of messages in the upper right corner of the application icon applicationIconBadgeNumber
2. The wait icon indicator on the status bar during networking operations. Waiting icon. NetworkActivityIndicatorVisible
3. Use UIApplication to open a resource
** Open a webpage:
[App openURL: [NSURL URLWithString: @ "http://ios.icast.cn"];
** Call
[App openURL: [NSURL URLWithString: @ "tel: // 10086"];
** Send a text message
[App openURL: [NSURL URLWithString: @ "sms: // 10086"];
** Send an email
[App openURL: [NSURL URLWithString: @ "mailto: // 12345@qq.com"];
4. Manage the status bar through UIApplication:
IOS7 can be used to control the status bar in two ways.
1> Controller- (BOOL)prefersStatusBarHidden
- (UIStatusBarStyle)preferredStatusBarStyle
2>. UIApplication
To use UIApplication for management, follow these steps:
1> Add a configuration item to the Info. plist file.
* View controller-based status bar appearance = NO,
2> then write the following code: // you can also call the method to set the animation.

app.statusBarHidden = YES;app.statusBarStyle
-3. UIApplicationDelegate introduction, program startup process 3. UIApplicationDelegate introduction, program startup process back to top

Set the proxy of the UIApplication object in the main function.
Apps are vulnerable to interference. Playing a game. A call is coming.
* Application lifecycle events (such as program startup and shutdown)
* System events (such as laidian)
* Memory warning
*... ...
** To handle these interference events, you must use the AppDelegate proxy object.
** Conclusion: the main function of AppDelegate is to process (Listen) various events of the application itself:
* The application has been started.
* The application enters the background.
* The application enters the foreground.
* Memory warning
* And so on. They are all application events.
** To become a proxy object for UIApplication, you must comply with the: UIApplicationDelegate protocol.
** Several proxy methods:
1.-(BOOL) application: didfinishlaunchingwitexceptions:
// The method is called after the app is started for the first time (when the app is started, a startup image is displayed. When the image is displayed and disappears, the method is called)
2.-(void) applicationDidEnterBackground :( UIApplication *) application
// Call this method when the program enters the background. (For example, if you press the Home key or call a phone number, the current program will enter the background .)
// In this method, you can save the current program data and pause the program operation.
3.-(void) applicationWillEnterForeground :( UIApplication *) application
// Called when the program enters the foreground again.
4.-(void) applicationDidReceiveMemoryWarning :( UIApplication *) application
// This event is triggered when a memory warning occurs.
After the program is started:
Didfinishlaunchingwitexceptions --> applicationDidBecomeActive
Press the home key to bring the program to the background: applicationWillResignActive ---> applicationDidEnterBackground
Let the program go to the main interface: applicationWillEnterForeground ---> applicationDidBecomeActive
Exit the program on the main interface: applicationDidEnterBackground ---> applicationWillTerminate
Exit in the background: applicationWillTerminate

 

-4. The UIWindow4.UIWindow object is returned to the top.

** UIWindow is a special type of UIView, and UIWindow is also inherited from UIView.
** Generally, an app only has one UIWindow object.
** 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.
** An iOS program is displayed on the screen because it has a UIWindow.
** For details about the relationship between UIWindow and Controller View, refer to Cocoa Touch Layer> UIKit> Guides> View Controller Programming Guide for iOS> View Controller Basics.
** During the creation process, choose UIWindow> UIViewController> UIView> Add UIView to the UIWindow object.

 

-5. process displayed on the program interface 5. process displayed on the program interface returns to the top

 

Use main. at this time, when the program is started, the UIWindow will be automatically created, and then according to main. create the corresponding controller in the storyboard file and view in the controller. then add the View of the Controller to the UIWindow. then we can see the interface.

If no storyboard is used for project startup, The UIWindow object and the corresponding controller will not be created after the application is started.

In the FinishLaunching of the app proxy class

Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; // create a controller, and then set the Controller to UIWidnowMKViewController * mkViewCotroller = [[MKViewController alloc] init]; // set hmVc to self. window root controller self. window. rootViewController = mkViewCotroller; // set this (self. window. window makeKeyAndVisible];

Note that:
Do not directly add the control to UIWindow. Instead, create a controller, add a child control to the view managed by the Controller, and set the Controller to UIWindow.
Cause:
1> UIWindow always exists until the application exits. All the child controls added to UIWindow will always be strongly referenced by UIWindow.
2> If the child control is directly added to the UIWindow, the events of all child controls must be monitored by the application proxy.
Actually, the corresponding controller should be used to listen for these events.
3> when the screen rotates, UIWindow listens to the rotation event and passes it to the controller. The Controller then rotates the corresponding sub-control. if you directly add a child control to the UIWindow, there is no controller and the Child control cannot listen for rotation events.

 

-6. Summary of the entire process of starting the program 6. Summary of the entire process of starting the program back to the top

(Summary of storyboard and storyboard)

No storyboard file 1. Call the main function.
2. Call the UIApplicationMain function.
3. Create a UIApplication object and an AppDelegate object
4. Set the proxy of the UIApplicatio object to an AppDelegate object.
5. The AppDelegate object starts to listen to "system events (Application events)" And enters "event loop ".
6. After the program is started, call application: didfinishlaunchingwitexceptions: method.
---- 7. Create in application: didfinishlaunchingwitexceptions: method:
* UIWindow
* Controller
* Set the root controller of UIWindow to the Controller just created.
* Display UIWindow
There is a storyboard file to return to the top 1. Call the main function.
2. Call the UIApplicationMain function.
3. Create a UIApplication object and an AppDelegate object
4. Set the proxy of the UIApplicatio object to an AppDelegate object.
5. The AppDelegate object starts to listen to "system events (Application events)" And enters "event loop"
6. After the program is started, call application: didfinishlaunchingwitexceptions: method.
---- 7. Create in application: didfinishlaunchingwitexceptions: method:
* The system automatically creates a UIWindow object.
* Locate the storyboard file (Main. storyboard) to be loaded based on the Main Interface configuration in the Info. plist file)
* Find the Controller class corresponding to Is Initial View Controller in Main. storyboard and create the Controller object.
* Create a view for the Controller Based on the configuration in the storyboard.
* Set the root controller (rootViewController) of UIWindow to the Controller you just created.
* Display UIWindow ([self. window makeKeyAndVisible]).

 

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.