UIApplication, analysis of Uiapplicationdelegate,uiapplicationmain

Source: Internet
Author: User

I. UIApplication, analysis of Uiapplicationdelegate,uiapplicationmain

* UIApplication's core role is to provide control and coordination during the operation of the iOS program.

* Each application has its own UIApplication object, and it is a singleton object.

* Some application-level operations can be performed with UIApplication objects.

* Demonstrate the use of uiapplication

> Get UIApplication object uiapplication *app = [UIApplication sharedapplication];

> Sets the Applicationiconbadgenumber property of the red number uiapplication the app icon.

After the iOS8 update, the error is prompted when setting Applicationiconbadgenumber, because the app is set after IOS8

The applicationiconbadgenumber of the program requires user authorization

The authorization method is as follows:

if ([[[[Uidevice Currentdevice] systemversion] doublevalue] >= 8.0) {

Uiusernotificationsettings *settings = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge Categories:nil];

[[UIApplication sharedapplication] registerusernotificationsettings:settings];

}

> Prevent screen from darkening, use cautiously, default to No 2.0 UIApplication idletimerdisabled property set to Yes

Use this feature sparingly, because it consumes very much power.

> Networking Indicator UIApplication's Networkactivityindicatorvisible property.

> Use uiapplication to manage the status bar (iOS7 previous status bar is managed by UIApplication, IOS7 later to controller management).

1), after iOS7, the status bar by default is to the controller to manage, controller implementation of the following two methods to control the status bar display, hide and style

/**

* Hide Status bar

*/

-(BOOL) Prefersstatusbarhidden {

return YES;

}

/**

* Change the status bar style

*/

-(Uistatusbarstyle) Preferredstatusbarstyle {

return uistatusbarstylelightcontent;

}

2), after iOS7, the status bar to UIApplication management, to set the view controller-based status bar appearance NO in Info.plist

UIApplication *app = [UIApplication sharedapplication];

/****** No animation ***********/

App.statusbarhidden = YES;

App.statusbarstyle = uistatusbarstylelightcontent;

/****** has animated ***********/

[App Setstatusbarhidden:yes Withanimation:uistatusbaranimationslide];

[App Setstatusbarstyle:uistatusbarstylelightcontent Animated:yes];

3), uiapplication the benefits of managing the status bar:

*, animation can be set

*, more flexible, you can set the status bar style anytime and anywhere.

> UIApplication's OpenURL: method. (Make a phone call, send a message, send an email (the simulator performs the first three actions), open the Web resource,

Open other apps (share), etc.)

* URL: The only path to a resource

* URL Composition: protocol header://Host domain name/path

Benefits of using application to open network resources: The system automatically recognizes what software is used to open the resource.

* Uiapplicationdelegate Object Introduction

One of the main tasks of the >uiapplicationdelegate object is to track the application's state changes, such as entering the foreground, backstage, visible, etc.

Application is up and ready

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {

NSLog (@ "Application loading complete");

return YES;

}

App is about to become inactive [lose focus]

-(void) Applicationwillresignactive: (uiapplication *) Application {

NSLog (@ "is about to become inactive [lose focus]");

In general, this method performs the following actions:

* Pause a task that is being performed

* No timer

* If the game should be suspended

}

Application into the background

-(void) Applicationdidenterbackground: (uiapplication *) Application {

NSLog (@ "app goes Backstage");

In general, this method performs the following actions:

* Save current app information and app status

* Save user data (write to sandbox)

* For games, save game points

* Abolition of timers

}

Apps coming into the foreground

-(void) Applicationwillenterforeground: (uiapplication *) Application {

NSLog (@ "coming into the foreground");

}

App becomes active

-(void) Applicationdidbecomeactive: (uiapplication *) Application {

NSLog (@ "app becomes active [get focus]");

}

Application is about to be destroyed

-(void) Applicationwillterminate: (uiapplication *) Application {

NSLog (@ "Application is about to be destroyed");

}

App receives a memory warning

-(void) applicationdidreceivememorywarning: (uiapplication *) Application {

NSLog (@ "app received memory warning");

}

* Uiapplicationmain Function Official Description:

1> Return Value

Even though an integer return type was specified, this function never returns. When users exits a IOS application by pressing the Home button, the application moves to the background.

return value

Although the return value specified by this function is cosmetic, this function never returns. When the user presses the home key to exit the iOS app, the app goes into the background.

2> Discussion

This function instantiates the Application object from the principal class and instantiates the delegate (if any) from the Given class and sets the delegate for the application. It also sets up the main event loop, including the application ' s run loop, and begins processing events. If the application ' s Info.plist file specifies a main nib file to is loaded, by including the Nsmainnibfile key and a Vali d nib file name for the value, this function loads that nib file.

From the official description of the function, it is possible to know that the function mainly does the following things:

Function Prototypes:

Uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname)

1) Create a Application object based on the class name specified by Principalclassname. If Principalclassname is nil, the UIApplication object is created by default.

2) Creates an object based on the class name specified by Delegateclassname and sets the object as an application proxy.

3) Turn on the event loop, including the application's loop run, and start processing events.

4) If the application's Info.plist file specifies the primary stroyboard file, this function loads the Stroyboard file.

UIApplication, analysis of Uiapplicationdelegate,uiapplicationmain

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.