iOS UIApplication

UIApplication是一个单例

// 获取UIApplication

UIApplication *app = [UIApplication sharedApplication];

//1. 隐藏状态栏

//    [app setStatusBarHidden:YES];

[app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

// 在iOS7以后,状态栏默认由控制器决定

// 隐藏状态栏 

注意:在info.plist里设置View controller-based status bar appearance 为Yes

//- (BOOL)prefersStatusBarHidden

//{

//    return YES;

//}

//- (UIStatusBarStyle)preferredStatusBarStyle

//{

//    return UIStatusBarStyleLightContent;

//}


// 2.UIApplication一般用来做一些应用级别的操作(app的提醒框,联网状态,打电话,打开网页,控制状态栏)

// 设置appIcon提醒数字,必须注册用户通知

app.applicationIconBadgeNumber = 10;

// 创建用户通知

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];

// 注册用户的通知

[app registerUserNotificationSettings:settings];

// 设置联网状态

app.networkActivityIndicatorVisible = YES;

// URL:资源路径

// URL:协议头://域名+路径  http,https,file,tel

// 协议头:

// 打开网页 @"http://www.baidu.com"

NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

[[UIApplication sharedApplication] openURL:url];

// 打电话 @"tel://%@",@"400-9697982"

NSString *str=[NSString stringWithFormat:@"tel://%@",@"400-9697982"];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

你可能感兴趣的:(iOS UIApplication)