12-Program Start principle

Source: Internet
Author: User

Program Start Principle Mastery
    • 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
    • Common Properties (the red part is the key you see when you open it with a text editor)
    • 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

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
    1. Through Uiviewcontroller management (each uiviewcontroller can have its own different status bar)
    2. 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
    1. Style of the status bar

-(Uistatusbarstyle) Preferredstatusbarstyle;

    1. 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
    1. 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"];

    • Open Other app Programs
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:
    1. Application lifecycle events (such as program startup and shutdown)

    2. System events (such as incoming calls)

    3. Memory warning ...

UIApplication and delegate

Uiapplicationdelegate

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);
    1. ARGC, argv: direct transfer to Uiapplicationmain for related processing can be

    2. 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

    3. Delegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol

    • 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.
    • 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 UIView object in your app (the keyboard that pops up 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

12-Program Start principle

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.