OBJECTIVE-C Study Notes: Program start principle

Source: Internet
Author: User

1.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, and cannot be deleted.

* In the project created by the older version of Xcode, the name of this profile 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, which is related to the localization of the Info.plist file.

* Common Properties (red is the key you see when opened 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

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

* Some global macros are generally defined in PCH files

* Add the following preprocessing directives in the PCH file, and then use log (...) in the 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

3.UIApplication

3.1: 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 UIApplication objects to perform some application-level operations

Common Properties of 3.2:uiapplication


Set the red reminder number in the upper right corner of the application icon @property (nonatomic) Nsinteger applicationiconbadgenumber; // set the visibility of the networking indicator @property (nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible;

The status bar in 3.3: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)

* 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


The style of the status bar -// visibility of the status bar -(BOOL) Prefersstatusbarhidden;

3.4: Use 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

3.5:OpenURL:

//UIApplication has a very powerful OpenURL: Method-(BOOL) OpenURL: (nsurl*) Url;openurl: Some of the functions of the method are//CallUIApplication *app =[UIApplication sharedapplication]; [App Openurl:[nsurl urlwithstring:@"tel://10086"]];//Send SMS[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

3.6: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 can handle events including: Application lifecycle events (such as program startup and shutdown), system events (such as incoming calls), memory warnings, etc.

* Uiapplicationdelegate Agreement

Each new project, there is a "appdelegate" word of the class, it is the agent of UIApplication

// The app receives a memory warning when called -(void) applicationdidreceivememorywarning: (uiapplication *) application; // when the app enters the background (such as by pressing the home button)-(void) Applicationdidenterbackground: (uiapplication *) application; // when the app is started, call -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions;

3.7:ios program start-up process

3.8:uiapplicationmain

* A uiapplicationmain function is executed in the main function.

int Uiapplicationmain (intchar *argv[], nsstring *principalclassname, NSString *delegateclassname);

* ARGC, argv: direct transfer to Uiapplicationmain for related processing can be

* 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

* 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 main Runloop (event loop) of the application 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

4.UIWindow

* UIWindow is a special kind of uiview, usually only one uiwindow in an app

* After the iOS program is started, 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

* Also say, 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 of the UIView objects in your app (usually input text pop-up keyboard, is 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 the UIWindow is not Keywindowview.window//  Get the UIWindow where a uiview is located

5. Finally attach the four object diagram

OBJECTIVE-C Study Notes: Program start principle

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.