The app Launcher principle for iOS development

Source: Internet
Author: User

iOS program start-up process

The complete procedure for starting a program is outlined below:

1.main function

2.UIApplicationMain

* Create UIApplication objects

* Create a UIApplication delegate object

3.delegate object starts processing (listening) system events (no storyboard)

* When the program is started, the agent's application:didfinishlaunchingwithoptions is called: method

* Create UIWindow in application:didfinishlaunchingwithoptions:

* Create and set UIWindow Rootviewcontroller

* Display window

3. According to Info.plist to obtain the most important storyboard file name, load the most important storyboard (with storyboard) (can be carried out in conjunction with the previous step)

* Create UIWindow

* Create and set UIWindow Rootviewcontroller

* Display attempts to

When you open a program in iOS, it starts with the steps shown

Uiapplicationmain function

A uiapplicationmain function is executed in the main function.
  // 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, the UIApplication class is used as the default value  //Delegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol  int uiapplicationmain (intchar *argv[], nsstring *principalclassname, NSString *delegateclassname);
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. what is uiapplication The UIApplication object is a symbol 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 the UIApplication object. With UIApplication objects, you can perform some application-level operations. Common Properties of UIApplication 1. Set the red reminder number in the upper right corner of the application icon
@property (nonatomic) Nsinteger applicationiconbadgenumber;

2. Setting the visibility of the networking indicator
@property (nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible;

The OpenURL method of UIApplication

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"];
2. Send SMS
UIApplication *app = [uiapplication sharedapplication];
[App Openurl:[nsurl urlwithstring:@ "sms://10086"];

3. Send an email

UIApplication *app = [uiapplication sharedapplication];
[App Openurl:[nsurl urlwithstring:@ "mailto://[email protected]"];
4. Open a Web resource
UIApplication *app = [uiapplication sharedapplication];
[App Openurl:[nsurl urlwithstring:@ "http://www.baidu.com"];
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 delegate agents 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

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, and it says that without UIWindow, no UI interface is visible. 1. There are two common ways to add 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
2. Common methods
-(void) Makekeywindow;
Make current UIWindow into Keywindow (main window)
-(void) makekeyandvisible; // make the current UIWindow into Keywindow and show it

3. How to get UIWindow

      • 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].windows
      • 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
[UIApplication Sharedapplication].keywindow
      • Get the UIWindow where a uiview is located
View.window

Four objects ( Uiapplication,appdelegate,uiwindow,uiviewcontroller) diagram

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. Info.plist Common Properties (red is the key you see when opened with a text editor) 1.Localiztion native Development Region (cfbundledevelopmentregion)-Localization related 2.Bun Dle display Name (cfbundledisplayname)-The name of the program displayed after installation, limited to 10-12 characters, if exceeded, will be displayed abbreviated name 3.Icon file (cfbundleiconfile)-app icon name, Typically icon.png 4.Bundle version (cfbundleversion)-the application's release number, each time a new version is posted to the App Store, this version number needs to be added 5.Main storyboard file base n Ame (Nsmainstoryboardfile)-the name of the main storyboard file 6.Bundle identifier (cfbundleidentifier)-Unique identification of the project, deployed to the real machine

The app Launcher principle for iOS development

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.