UIApplication Introduction:
- The UIApplication object is a symbol of the application.
- Each application has its own UIApplication object, and it is a singleton.
- The first object created after an iOS program is started is the UIApplication object.
UIApplication *app = [UIApplication sharedApplication];this singleton object can be obtained by the.
- Some application-level operations can be performed using UIApplication objects.
Some application-level operations can be performed using UIApplication objects.
Remind
- Setting the visibility of networking indicators
@property (nonatomic,getter=isnetworkactivityindicatorvisible) BOOL networkactivityindicatorvisible; // code implementation and effects app.networkactivityindicatorvisible= YES;
Networking indicator Display
-
Manage status bar
Starting with IOS7, the system provides 2 ways to manage the status bar
A. Through Uiviewcontroller management (each uiviewcontroller can have its own different status bar) in IOS7, the status bar is managed by the Uiviewcontroller by default, and Uiviewcontroller implements the following methods to light Manage the visibility and style of the status bar
状态栏的样式 - (UIStatusBarStyle)preferredStatusBarStyle;
状态栏的可见性 -(BOOL)prefersStatusBarHidden;
#pragma mark-设置状态栏的样式-(UIStatusBarStyle)preferredStatusBarStyle{ //设置为白色 //return UIStatusBarStyleLightContent; //默认为黑色 return UIStatusBarStyleDefault;}#pragma mark-设置状态栏是否隐藏(否)-(BOOL)prefersStatusBarHidden{ return NO;}
B. Through UIApplication management (the status bar of an application is unified by it) if you want to use uiapplication to manage the status bar, first you have to modify the Info.plist settings, add the selected row, and set to No, this article is detailed in the iOS Applicati On to manage battery bar status
Settings for Info.plist
Code:
//通过sharedApplication获取该程序的UIApplication对象UIApplication *app=[UIApplication sharedApplication];//设置状态栏的样式//app.statusBarStyle=UIStatusBarStyleDefault;//默认(黑色)//设置为白色+动画效果[app setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];//设置状态栏是否隐藏app.statusBarHidden=YES;//设置状态栏是否隐藏+动画效果[app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
C. Summary
If the style of the status bar is set only once, it is managed with uiapplication, and the uiapplication can provide an animated effect;
If the status bar is hidden, The style is different then use each controller to manage its own status bar.
-
OpenURL: Method
UIApplication has a very powerful OpenURL: Method
-(BOOL) OpenURL: (nsurl*) URL;
OpenURL: Some of the features of the method are
uiapplication *app = [ uiapplicationsharedapplication]; call [app Openurl:[ "tel://110"], SMS [app Openurl:[ "sms://10086"]; email [app Openurl:[ "mailto://[email protected]"]; open a web resource [app Openurl:[nsurl urlwithstring:@ "HTTP +/" Www.baidu.com "]; open another APP OpenURL method, you can open the other app.
System internally based on different headers to make different corresponding 。
-
Judging the running state of a program
//判断程序运行状态 /* UIApplicationStateActive, UIApplicationStateInactive, UIApplicationStateBackground */UIApplication *app = [UIApplication sharedApplication];if(app.applicationState ==UIApplicationStateInactive){ NSLog(@"程序在运行状态"); }
- Prevent the screen from darkening into hibernation
//阻止屏幕变暗,慎重使用本功能,因为非常耗电。 UIApplication *app = [UIApplication sharedApplication]; app.idleTimerDisabled =YES;
UIApplication Delegate
When the app receives interference, such as a call in the program's operation, it generates some system events, and Uiapplicaiton notifies its proxy delegate object, allowing delegate agents to handle these system events.
The time that delegate can handle includes
1. Application lifecycle events (such as program startup and shutdown)
2. System events (such as incoming calls)
3. Memory warning (more useful)
每当我们创建项目时,程序中的AppDelegate文件就是UIAppliacation的代理,我们可以发现它已经遵守了UIApplicationDelegate。
@interface AppDelegate : UIResponder <UIApplicationDelegate>
Now let's take a look at the Appdelegate method.
Appdelegate: Monitoring the life cycle of an applicationThe following approach is the life cycle approach of the applicationThe Appdelegate method is called when the application starts to complete-(BOOL) Application: (UIApplication *) Application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions {NSLog (@ "%s", __func__);ReturnYES;}Called when the application loses focus-(void) Applicationwillresignactive: (UIApplication *) Application {NSLog (@ "%s", __func__);}Called when the application enters the background-(void) Applicationdidenterbackground: (UIApplication *) Application {NSLog (@ "%s", __func__);Save some information}//called when the application enters the foreground-(void) Applicationwillenterforeground: ( Span class= "hljs-built_in" >uiapplication *) application {nslog ( @ "%s", __func__);} //call //can interact with the user only when the application fully acquires focus-(void) applicationdidbecomeactive: (uiapplication *) Application { Span class= "hljs-built_in" >nslog (@ "%s", __func__);} //when the application is closed-(void) Applicationwillterminate: (uiapplication *) application {}//called when a memory warning is received-( void) applicationdidreceivememorywarning: (UIApplication * ) application{}
iOS big God class Note 03-uiapplication