Info.plist, PCH, and four objects (UIApplication, Uiapplicationdelegate, UIWindow, Uiviewcontroller)

Source: Internet
Author: User
Tags file info uikit

directory of this document
    • 1. Program configuration file Info.plist, global header file PCH
    • 2. Application Object UIApplication Introduction
    • 3.UIApplicationDelegate Introduction, program start-up process
    • 4.UIWindow objects
    • 5. Process of Program Interface display
    • 6. Summary procedure to start the complete process
-1. Program configuration file Info.plist, global header file PCH1. Program configuration file Info.plist, global header file PCHBack to Top

The content in the Info option in the project configuration is actually a copy of the contents of the Info.plist file, and Info.plist contains many configuration information about the project startup parameters. It should be noted that if you want to add a custom plist file to your project, you should make the file name contain no info. Info.plist modification is the same as other plist file modification, which is the modification of key-value pairs. However, it is important to note that when you open the file by using source code, the key name is not the same as when you opened it in plist mode. In the XML source file discussion, the key name is divided into the following types:

Core Foundation Keys
The keys of this class are characterized by CF, which represents the core Foundation and describes some common behavior items
Lanch Services Keys
Loads the service item, provides the configuration that the app loads depends on, and describes how the app launches.
Cocoa Keys
The cocoa framework or cocoa touch framework relies on these keys to identify higher-level configuration items, such as the app's main
NIB file, main class. These key descriptions affect how the cocoa and cocoa touch framework Initializes and runs the app.
UIKit Keys
Describes the behavior of iOS apps, which are dependent on info for each iOS app.
plist keys to communicate with the iOS system. Xcode provides the generated plist file that provides the more important keys that all apps need. However, the app may need to extend the default plist to describe more information, such as the default rotation direction after a custom app is launched, to identify whether the app supports file sharing, and so on.
OS X Keys
Describes the behavior of Mac apps.

Here are some of the common key meanings:

1.Localiztion native development region --- CFBundleDevelopmentRegionLocalization related, if the user location does not have the corresponding language resources, then use the value of this key as the default
2.Bundle display name --- CFBundleDisplayNameSets the name that is displayed after the program is installed. The program name is limited to 10-12 characters, and if exceeded, the abbreviated name is displayed.
3.Executaule dile -- CFBundleExecutableName of the program installation package
4.Bundle identidier --- CFBundleIdentidier The unique identification string for the bundle, the string formatted like Com.yourcompany.yourapp, and if so? Use the simulator to run your application, this field is useless, if you need to put your should? Deploy to the device, you must be a certificate, and when the certificate is generated, You need to add the app IDs on Apple's website. There is a field bundle Identidier, if the bundle Identidier is a complete string, then this field in the file must be exactly the same as the latter if the app The field in IDs contains a wildcard *, then the string in the file must conform to the description of the latter.
5.InfoDictionary version --- CFBundleInfoDictionaryVersion Info.plistVersion information in format
6.Bundle name --- CFBundleNameProduct Name
7.Bundle OS Type code -- CFBundlePackageType? To identify the four-letter long code of a bundle type
8.Bundle versions string, short --- CFBundleShortVersionString? The version string of the bundle to the user market
9.Bundle creator OS Type code --- CFBundleSignatureFour-letter long code to identify the creator
10.Bundle version --- CFBundleVersionThe program version number, which will be added to the App store each time a new version of the application is deployed.
11.Application require iPhone environment -- LSRequiresIPhoneOSUsed to indicate whether the package can only run on iphone OS systems. Xcode automatically joins 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 main nib file.
13.supported interface orientations -- UISupportedInterfaceOrientationsThe device orientation that the program supports by default.

PCH file, which is prefix header files. is the global header file after the program is run, when the file is added, you can directly use the various contents of the file, such as macro definitions and constants and some common classes, without using # include in other files or importing the file with #import. The PCH file can be used directly before XCODE5, and in the 6.0-language header entry in the Apple LLVM prefix entry in build settings after Xcode6, the directory in which the PCH file is set is $ ( srcroot)/corresponding folder name/prefixheader.pch, for example, can be set directly in the root directory $ (srcroot)/prefixheader.pch

When there are more nslog in the program, it can cause a lot of performance problems (NSLog is an IO operation), which is very bad for the publisher, if all the NSLog in the program are found and deleted or commented, the project item is huge, so it can be used to set a conditional compilation in the PCH. If the NSLog is normal code in debug state, ignore them if it is in the release state.

#ifdef debug#define NSLog (...); NSLog (__va_args__); #else # define NSLOG (...); #endif

In debug state, the contents of __va_args__ will be replaced by ... (This is the method commonly used in extracting method parameters in the macro definition), while in the publishing state, the NSLog (...) is ignored directly.

iOS development will inevitably encounter some OC and C mixed, when the PCH file is used, the C file will not recognize the above conditional compilation and #import instructions, this time should use another conditional compilation to avoid problems:

#ifdef __objc__    #import <UIKit/UIKit.h>    #import <Foundation/Foundation.h> #endif
-2. Application Object UIApplication Introduction2. Application Object UIApplication IntroductionBack to Top

UIApplication is a singleton class that can do some application-level operations
1. The number of message bars in the upper right corner of the app icon Applicationiconbadgenumber
2. When connected, the wait icon indicator on the status bar. Waiting icon. Networkactivityindicatorvisible
3. Open a resource with uiapplication
* * Open a webpage:
[App Openurl:[nsurl urlwithstring:@ "http://ios.icast.cn"];
* * Call
[App Openurl:[nsurl urlwithstring:@ "tel://10086"];
* * Send SMS
[App Openurl:[nsurl urlwithstring:@ "sms://10086"];
* * Send Email
[App Openurl:[nsurl urlwithstring:@ "Mailto://[email protected]"];
4. Manage the status bar via uiapplication:
IOS7 start to control the status bar in two ways
1> Controller- (BOOL)prefersStatusBarHidden
- (UIStatusBarStyle)preferredStatusBarStyle
2>. UIApplication
If you want to manage through uiapplication, here are the steps:
1> Add a configuration item to the Info.plist file
* View controller-based status bar appearance = NO,
2> then write the following code://can also be in the form of a method call, so that you can set the animation

App.statusbarhidden = Yes;app.statusbarstyle
-3.uiapplicationdelegate Introduction, program startup process3.UIApplicationDelegate Introduction, program start-up processBack to Top

The UIApplication object's proxy is set in the main function.
Apps are susceptible to interference. Is playing a game, a phone call came over.
* Application lifecycle events (such as program startup and shutdown)
* System events (such as incoming calls)
* Memory Warning
* ... ...
* * To deal with these interference events, we need to use the Appdelegate proxy object.
* * Summary: The main role of Appdelegate is to process (listen) The various events of the application itself:
* Application started
* App goes backstage
* App enters the foreground
* Memory Warning
* And so on, are some of the events of the application itself
* * To be a proxy object for uiapplication, you must comply with: Uiapplicationdelegate protocol.
* * Several methods introduced in the agent:
1.-(BOOL) Application:didfinishlaunchingwithoptions:
It will be called when the app is first launched (when the program starts, it will display a boot image, and when the picture is finished and disappears, it will start calling this method)
2.-(void) Applicationdidenterbackground: (uiapplication *) application
This method is called when the program enters the background. (For example: Press the Home button, or a phone call, the current program will enter the background.) )
In this method can be done to save the current program data, pause the operation of the program.
3.-(void) Applicationwillenterforeground: (uiapplication *) application
Called when the program enters the foreground again.
4.-(void) applicationdidreceivememorywarning: (uiapplication *) application
The event is triggered when a memory warning occurs.
After the program starts:
Didfinishlaunchingwithoptions-->applicationdidbecomeactive
Press the home key to get the program into the background: applicationwillresignactive--->applicationdidenterbackground
Let the program go to the main interface: Applicationwillenterforeground--->applicationdidbecomeactive
Let the program exit at the main interface: Applicationdidenterbackground--->applicationwillterminate
Exiting in the background: applicationwillterminate

-4.uiwindow4.UIWindow ObjectsBack to Top

* * UIWindow is a special kind of UIView, UIWindow is also inherited from UIView.
* * Usually an app will only have one UIWindow object.
* * 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
* * Find in documents: Cocoa Touch Layer, UIKit, Guides, view Controller Programming Guide for IOS, view Controller Basics a picture of the relationship between UIWindow and controller view.
* * Add UIView to the UIWindow object, UIView, Uiviewcontroller, UIWindow, creation process.

-5. The process of program interface display5. Process of program Interface displayBack to Top

When the boot is configured to use Main.storyboard, at this point, when the program is finished, the UIWindow is created automatically, and then the corresponding controller is created according to the Main.storyboard file, and the view in the controller. The controller's view is then added to the UIWindow. Then we see the interface.

If no storyboard is used when the project is configured to start, then the application does not create the UIWindow object, the corresponding controller, and so on when it is finished. You need to create it yourself.

In the finishlaunching of the app proxy class

Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];    Create a controller and set the controller to Uiwidnowmkviewcontroller *mkviewcotroller = [[Mkviewcontroller alloc] init];// Set Hmvc to Self.window's root controller Self.window.rootViewController = mkviewcotroller;//Set this (Self.window) as the main window and display it [ Self.window makekeyandvisible];

It is important to note that:
Instead of adding the control directly to the UIWindow, create the controller now, add the child controls to the view managed by the controller, and then set the controller to UIWindow.
Reason:
1> UIWindow will always exist until the application exits. All child controls added to the UIWindow are always uiwindow strong references.
2> if the direct handle is added to UIWindow, all child control events need to be monitored by the application proxy.
Actually, the corresponding controller should be allowed to listen to these events.
3> when the screen rotates, the UIWindow hears the rotation event and passes it to the controller, which then rotates the corresponding child control. If you add child controls directly to UIWindow, there is no controller and the child controls cannot listen for rotation events.

-6. Summary procedure to start the complete process6. Summary procedure to start the complete processBack to Top

(with storyboard and no storyboard separate summary)

No Storyboard file1. Call the main function.
2. Call the Uiapplicationmain function.
3. Creating UIApplication objects, Appdelegate objects
4. The proxy setting for the Uiapplicatio object is the Appdelegate object.
5. The Appdelegate object starts listening for "system events (application events)" and goes to "event loop".
6. Call Application:didfinishlaunchingwithoptions After the program is started: method.
----7. In the Application:didfinishlaunchingwithoptions: method, create:
* UIWindow
* Controller
* Set UIWindow root controller is the controller you just created
* Show UIWindow
There are storyboard filesBack to top of 1. Call the main function.
2. Call the Uiapplicationmain function.
3. Creating UIApplication objects, Appdelegate objects
4. The proxy setting for the Uiapplicatio object is the Appdelegate object.
5. The Appdelegate object starts listening for "system events (application events)" and goes to "event loop"
6. Call Application:didfinishlaunchingwithoptions After the program is started: method.
----7. In the Application:didfinishlaunchingwithoptions: method, create:
* The system automatically creates UIWindow objects.
* Depending on the info.plist file configuration (Main Interface), locate the storyboard file (Main.storyboard) that needs to be loaded
* Locate the Controller class for the IS Initial View controller in Main.storyboard to create the controller object.
* Create a view for the controller according to the configuration in storyboard.
* Set the UIWindow root controller (Rootviewcontroller) to the controller you just created.
* Display UIWindow ([Self.window makekeyandvisible]).

Info.plist, PCH, and four objects (UIApplication, Uiapplicationdelegate, UIWindow, Uiviewcontroller)

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.