The principle and uiapplication of program starting in UI advanced

Source: Internet
Author: User

uiapplication Object Description:1>a uiapplication representative is an application, and it is a singleton. **an object used to encapsulate an entire application, such as what to do when the application executes to a certain period, the life cycle, and so on. 2>get UIApplication object: [UIApplication sharedapplication]; (singleton)/** Verify the singleton mode, reference code:-(void) viewdidload {[Super viewdidload];                                            UIApplication *APP1 = [UIApplication sharedapplication];                                            UIApplication *app2 = [UIApplication sharedapplication];                  NSLog (@ "%p----%p", App1, APP2); }                                    */                                        3>when an iOS program starts, the first object that is created first is the UIApplication object. 4>with UIApplication, you can do some application-level operations. *application-level actions:1>QQ has a message when the top right corner of the message bar number. //gets the UIApplication object. UIApplication *app =[UIApplication sharedapplication]; //set the top right corner with 10 messagesApp.applicationiconbadgenumber =Ten; //Suppress MessageApp.applicationiconbadgenumber =0; /** Reference Code://When the button is clicked, set the top right message-(ibaction) Click: (ID) Sender { Get UIApplication object UIApplication *app = [uiapplication                                                                                       Sharedapplication];                             The IOS 8 system requires user permission to set up notifications. Uiusernotificationsettings *settings = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge                                                          Categories:nil];                                                          [App Registerusernotificationsettings:settings]; App.applicationiconbadgenumber = 10; There are 10 messages//App.applicationiconbadgenumber = APP.APPLICATIONICONBADG ENumber > 0? 0:10;                                                   There are 10 messages}*/                                                                           2>the wait icon indicator on the status bar when connected to a network operation.                        Waiting icon. UIApplication*app =[UIApplication sharedapplication]; App.networkactivityindicatorvisible=YES; 3>To open a resource with uiapplication:**The system will automatically open with an app based on protocol recognition. UIApplication*app =[UIApplication sharedapplication]; **Open a webpage: [App Openurl:[nsurl urlwithstring:@"http://ios.icast.cn"]]; **call [App Openurl:[nsurl urlwithstring:@"tel://10086"]]; **texting [App Openurl:[nsurl urlwithstring:@"sms://10086"]]; **Email [app Openurl:[nsurl urlwithstring:@"Mailto://[email protected]"]]; **You can also use the OpenURL method to open other apps and call each other between different apps. * * US 美图秀秀, click to share"Sina Micro-blog"Open it"Sina Micro-blog"Select Account, Jump back"Mei 美图秀秀", start sharing4>manage the status bar with UIApplication:**since IOS7 has been able to control the status bar in two ways1>Controller*through Uiviewcontroller management (each uiviewcontroller can have its own different status bar) *the following methods need to be implemented in the controller:/** Reference Code://Whether to hide the "status bar"-(BOOL) Prefersstatusbarh                                     Idden {return NO;                                     }//style of the status bar                                        -(Uistatusbarstyle) Preferredstatusbarstyle {                                     White return uistatusbarstylelightcontent; }                                                                          */                                2>uiapplication*managed by uiapplication (the status bar of an application is unified by it)**iOS7 Start status bar by default to the controller to manage, if you want to manage through uiapplication, the steps are as follows:1>Add a configuration item to the Info.plist file* View controller-based status bar appearance =NO,2>then write the following code:/** Reference Code:-(ibaction) Click: (ID) Sender {                                                                                  UIApplication *app = [UIApplication sharedapplication]; Sets whether the status bar is hidden//app.statusbar                                         Hidden = YES;                                                                                  Animated way//[app Setstatusbarhidden:yes Withanimation:uistatusbaranimationslide];                                         Set the status bar to appear white                                         App.statusbarstyle = uistatusbarstylelightcontent;                                         Animated way//[app Setstatusbarstyle:uistatusbarstylelightcontent Animated:yes];                                                                        }           */                                                              5.           Uiapplicationdelegate Introduction. **The appdelegate file after the project is created is the proxy object for uiapplication. *and the proxy object has been set up, without us having to set it manually. *settings made in the main function/** int main (int argc, char * argv[]) {@autoreleasepool {                      Sets the startup UIApplication object, and the corresponding proxy object appdelegate.                  Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class])); }                                    */**apps are susceptible to interference.                Is playing a game, a phone call came over. *Application lifecycle events (such as program startup and shutdown)*system events (such as incoming calls)*Memory Warning*...**to deal with these interference events, we need to use the Appdelegate proxy object. **Summary: The main function of appdelegate is to process (listen) The various events of the application itself:*Application Startup*application into the background*application into the foreground*Memory Warning*and so on, are some of the events of the application itself**To be a proxy object for uiapplication, you must comply with the following: Uiapplicationdelegate protocol. **Several methods in the agent are described:1. -(BOOL) application:didfinishlaunchingwithoptions://it will be called when the app is first launched (when the program starts, it will display a boot image, and when the picture is finished and disappears, it will start calling this method)                                                                     2. - (void) Applicationdidenterbackground: (UIApplication *) Application//This method is called when the program enters the background. (For example: Press the Home button, or a phone call, the current program will enter the background.) )//in this method can be done to save the current program data, pause the operation of the program.                                                                      3. - (void) Applicationwillenterforeground: (UIApplication *) Application//called when the program enters the foreground again.                                                                      4. - (void) Applicationdidreceivememorywarning: (UIApplication *) Application//The event is triggered when a memory warning occurs.                              6.       Description of the Uiapplicationmain function. /** Method Name: int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegatecla                Ssname); Parameter description: argc: Use the argc of the main function to argv: Use the argv of the main function to Principalclassname: Specify the Application class name (symbol of the app), which must be uiapplicatio                        N (or subclass), if Nil, uses the UIApplication class as the default value Delegateclassname: Specifies the application's proxy class, uiapplicationdelegate the method defined in the protocol, and implements in that class The Uiapplicationmain function will: 1> creates a UIApplication object based on Principalclassname 2> creates a del from Delegateclassname Egate the object and assigns the delegate object to the delegate property in the UIApplication object, the Uiapplicationmain function returns the default when the program exits gracefully.            Call mode: Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);                Equivalent to Uiapplicationmain (argc, argv, @ "uiapplication", @ "Appdelegate");                * * The proxy parameter must be passed, if nil, the "black screen" is displayed. */                                                                                         7. iOS program startup process.             Refer to the pictures on the PPT. 1>Open the program. 2>call the main function. 3>called in the main function: the Uiapplicationmain () function. *In the Uiapplicationmain () function:1. Create a UIApplication object2. Create a Appdelegate proxy object3. Set the Appdelegate proxy object to the UIApplication object. 4. Program started: Trigger Application:didfinishlaunchingwithoptions event. 5. The Uiapplicationmain () function opens a"Dead Loop (event loop)", so the program does not quit and we can use it arbitrarily. In this"Dead Loop (event loop)"The program constantly listens to the user's various events, processing (relying on"Event Queue"implementation). 4> Program exits.

The principle and uiapplication of program starting in UI advanced

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.