First, UIApplication
1. Brief introduction
(1) The UIApplication object is a symbol of the application, and a UIApplication object represents an application.
(2) Each application has its own UIApplication object, and is a singleton, if you try to create a new UIApplication object in the program, then the error prompt.
(3) This singleton object can be obtained by [UIApplication Sharedapplication].
(4) The first object created after an iOS program is started is the UIApplication object, and there is only one.
(5) Using UIApplication object, can carry on some application level operation.
2. Code examples for application-level operations
(1) Set the red reminder number in the upper right corner of the application icon (obsessive-compulsive nightmare)
1 uiapplication *app = [uiapplication Sharedapplication]; 2 Create notification 3 uiusernotificationsettings *setting = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge Categories:nil]; 4 Registration notification 5 [app Registerusernotificationsettings:setting]; 6 Set AppIcon reminder number 7 app.applicationiconbadgenumber = 200 ;
(2) can open Web page (drag a button in storyboard, listen button)
1 -(ibaction) Btnclick: (ID) sender {2// open page 3 uiapplication *app = [uiapplication sharedapplication]; 4 Nsurl *url = [Nsurl urlwithstring:@ "https://www.baidu.com"]; 5 [app Openurl:url]; 6 }
(3) can display the network status (has been in the circles)
1 UIApplication *app = [uiapplication sharedapplication]; 2 // set up Networking status 3 app.networkactivityindicatorvisible = YES;
(4) Set the status bar color (not see how much change, but it does have this method)
1 -(uistatusbarstyle) preferredstatusbarstyle2{3// set to White 4 return uistatusbarstylelightcontent; 5 // default is black 6 return Uistatusbarstyledefault; 7 }
(5) You can hide the status bar
But I tried the code did not succeed (-(BOOL) Prefersstatusbarhidden, etc. including the other two ways) but add the status bar is initially hidden Yes in info.plist.
(6) is said to be able to call, send text messages, e-mail and many other features, I tried the next online to the code, have not succeeded, have to know how to share under.
Self-learning iOS development small feature VI: uiapplication