IOS UIApplication 可以做得事情、

直接上代码,里面注释相对详细。

@interface ViewController ()
- (IBAction)applicationAction:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor greenColor]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)applicationAction:(id)sender {
    UIApplication *app=[UIApplication sharedApplication];
    //1.改变App图标右上角的数字显示,0表示不显示.
    app.applicationIconBadgeNumber=0;
    //ios8以上,需要注册registerUserNotification授权才可以改变
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    
    //2.设置是否显示联网指示
    app.networkActivityIndicatorVisible=YES;
    
    //3.通过UIApplication管理。统一设置,只能设置一次,有动画;
    app.statusBarHidden=YES;
    [app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    app.statusBarStyle=UIStatusBarStyleLightContent;
    [app setStatusBarStyle:UIStatusBarStyleLightContent animated:UIStatusBarAnimationSlide];
    
    //4.可以打开URL---打电话,发送短信,打开网页,邮件,打开其他app程序 都是打开URL的操作
    //打电话
    [app openURL:[NSURL URLWithString:@"tel://10086"]];
    
    //发短信
    [app openURL:[NSURL URLWithString:@"sms://10086"]];
    
    //发邮件
    [app openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
    
    //打开一个网页资源
    [app openURL:[NSURL URLWithString:@"http://ios.itcast.cn"]];
    
    //打开其他app程序   openURL方法,可以打开其他APP。
}

//通过UIViewController管理。每个界面都可以设置一个不同的状态,无动画;

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

-(BOOL)prefersStatusBarHidden{
    return NO;
}
@end


你可能感兴趣的:(ios散笔)