How the program starts in iOS

Source: Internet
Author: User

first, the principle of program start1. 首先找到程序入口,执行main函数

Uiapplicationmain, Main

2. UIApplicationMain底层做事情

1> Creating UIApplication Objects

2> creates a proxy object for the uiapplication, and assigns a value to the UIApplication object Proxy property

3> Open the main run loop, function receive event, keep the program running

4> load Info.plist, judging by the wood has a designated Main.storyboard, if specified will go to load

3. Create UIWindow

1> load Info.plist, determine if there is no specified Main.storyboard, specify the Main.storyboard, will go to load Main.storyboard, execute Main.storyboard when created window, loads the controller, sets the window's root controller, and displays the window.

2> After the Info.plist file is loaded, if no main.storyboard is specified, the window is created when the program starts to complete. ( 手动创建窗口 )

1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2     //note points displayed by the window:3     //1. Be sure to quote strongly4     //2. If the control is to be displayed, it must have a size5 6     //1. Create a window7Self.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];8 9     //2. Create the root controller in the settings window of the root controllerTenUiviewcontroller *VC =[[Uiviewcontroller alloc] init]; One  A     //The root controller of the window is set, and the root controller's view is automatically added to the window, and the controller's view has a rotation function -Self.window.rootViewController =VC; -  the     //3. display window -     //makekeyandvisible: Makes the window the main window of the application and displays the window - [Self.window makekeyandvisible]; -  +     returnYES; -}

Second, uiapplication

1> UIApplication object is the symbol of the application

2> each application has its own UIApplication object, and it is a singleton. This singleton object can be obtained by [UIApplication Sharedapplication].

3> the first object created after an iOS program is started is the UIApplication object

4> uses UIApplication objects to perform some application-level operations

1. Reminder numbers for app images
1    //get the symbol of the app2UIApplication *app =[UIApplication sharedapplication];3 4     //reminder numbers for app pictures5App.applicationiconbadgenumber = -;6 7     //Create a Notification object8Uiusernotificationsettings *settings =[uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge categories:nil];9     //Registered user NotificationTen[App Registerusernotificationsettings:settings];
2. Networking Status
1     // Networking Status 2     app.networkactivityindicatorvisible = YES;
3. Open resources, phone, web, SMS
1 // Open Web page 2 nsurl *url = [Nsurl urlwithstring:@ "http://www.baidu.com"]; 3 [app Openurl:url];
4. Setting the status bar  在iOS7之后,状态栏默认交给控制器处理
1 //hiding the status bar2-(BOOL) Prefersstatusbarhidden3 {4     returnYES;5 }6 //style of the status bar7-(uistatusbarstyle) Preferredstatusbarstyle8 {9     returnuistatusbarstylelightcontent;Ten}

那么在iOS7之后如何设置用UIApplication对象管理状态栏:

(在info.plist中添加一个字典View controller-based status bar appearance = NO)


 使用UIApplication对象管理状态栏的好处
 1.统一管理.(控制器很多的情况下用控制器不好管理)

//     App.statusbarhidden = YES;

 2. 隐藏状态栏可以设置动画

1   [App Setstatusbarhidden:yes Withanimation:uistatusbaranimationslide];

---restore content ends---

How the program starts in iOS

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.