<1>UIApplication的对象是单例对象 类方法:UIApplication *app = [UIApplication sharedAppplication]
<2>UIScreen的对象是单例对象 类方法:UIScreen *screen = [UIScreen mainScreen]
UIApplication的代理的协议的一些操作:
启动应用程序,代理帮助实现的程序状态的转换
UIApplication 应用程序对象的常用设置
(1)设置应用程序图标右上角的红色提醒数字(如QQ消息的时候,图标上面会显示1,2,3条新信息等) Badge
@property(nonatomic) NSInteger applicationIconBadgeNumber;
(2)设置联网指示器的可见性
@property(nonatomic,getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;
(3)说明:其实状态栏的管理,每一个单独的视图控制器可以管理,也可以让唯一的UIApplication的对象统一管理。
方式一:app统一管理:
状态栏的样式 -(UIStatusBarStyle)preferredStatusBarStyle;
app.statusBarStyle=UIStatusBarStyleDefault;//默认(黑色)
状态栏的可见性 -(BOOL)prefersStatusBarHidden;
app.statusBarHidden=YES //隐藏
方式二:每一个视图控制器单独管理:
//隐藏状态栏-(BOOL)prefersStatusBarHidden
{
return NO;
}
//设置状态栏的样式
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
(4)UIApplication有个功能十分强大的openURL:方法
URL:统一资源定位符,用来唯一的表示一个资源。
URL格式:协议头://主机地址/资源路径
-(BOOL)openURL:(NSURL*)url;
-openURL:方法的部分功能有
打电话 [app openURL:[NSURLURLWithString:@"tel://10086"]];
发短信 [app openURL:[NSURLURLWithString:@"sms://10086"]];
发邮件 [app openURL:[NSURLURLWithString:@"mailto://12345@qq.com"]];
打开一个网页资源 [app openURL:[NSURLURLWithString:@"http://www.baidu.com"]];
以下是代码的具体体现:
1 #import "ViewController.h" 2 3 @interface ViewController () 4 5 @end 6 7 @implementation ViewController 8 9 - (void)viewDidLoad { 10 [super viewDidLoad]; 11 // Do any additional setup after loading the view, typically from a nib. 12 [self.view setBackgroundColor:[UIColor blackColor]]; 13 } 14 15 - (void)didReceiveMemoryWarning { 16 [super didReceiveMemoryWarning]; 17 // Dispose of any resources that can be recreated. 18 } 19 //每一个视图控制器单独控制自己的状态栏 20 //隐藏状态栏 21 -(BOOL)prefersStatusBarHidden 22 { 23 return NO; 24 } 25 26 //设置状态栏的样式 27 -(UIStatusBarStyle)preferredStatusBarStyle 28 { 29 return UIStatusBarStyleLightContent; 30 } 31 @end
Application对象完成的各种功能:
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // Override point for customization after application launch. 3 4 //在iOS8中,必须经过用户允许才能设置badge/alert/sound 5 UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge |UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil]; 6 7 UIApplication *app = [UIApplication sharedApplication]; 8 [app registerUserNotificationSettings:setting]; 9 10 //设置应用程序图标上显示的提醒数字 11 app.applicationIconBadgeNumber = 10; 12 13 //设置联网指示器的可见性(默认是NO) 14 app.networkActivityIndicatorVisible = YES; 15 16 //设置状态栏的样式 17 app.statusBarStyle = UIStatusBarStyleLightContent; 18 19 //隐藏状态栏 20 app.statusBarHidden = NO; 21 22 //openURL功能(URL统一资源定位符) 23 //1.打电话 24 [app openURL:[NSURL URLWithString:@"tel://10086"]]; 25 26 //2.发短信 27 [app openURL:[NSURL URLWithString:@"sms://10086"]]; 28 29 //3.发邮件 30 [app openURL:[NSURL URLWithString:@"mailto://1360074459@qq.com"]]; 31 32 //4.打开网络资源 33 [app openURL:[NSURL URLWithString:@"http://www.baidu.com"]]; 34 35 //5.打开其他的应用程序 36 [app openURL:[NSURL URLWithString:@"prefs:"]]; 37 38 return YES; 39 }