UIApplication的常见设置
- (void)viewDidLoad {
[super viewDidLoad];
UIApplication *app = [UIApplication sharedApplication];
//app提醒数字,必须注册用户通知
app.applicationIconBadgeNumber = 1;
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
[app registerUserNotificationSettings:setting];
//app联网状态提醒
app.networkActivityIndicatorVisible = YES;
self.view.backgroundColor = [UIColor greenColor];
}
////由控制器管理隐藏最顶部的状态栏
//-(BOOL)prefersStatusBarHidden
//{
// return YES;
//}
//-(UIStatusBarStyle)preferredStatusBarStyle
//{
// return UIStatusBarStyleDefault;
//}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UIApplication *app = [UIApplication sharedApplication];
/**
* 在info.plist文件中添加 View controller-based status bar appearance Value: NO(状态栏不再由控制器管理,改为UIApplication管理)
*/
[app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
UIApplication生命周期方法
//程序启动完成调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
//当app失去活跃的时候调用
- (void)applicationWillResignActive:(UIApplication *)application
{
}
//当app进入后台的时候调用,app被打断的时候,在这里保存一些需要用到的数据
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
//当app进入前台的时候
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
//当app活跃的时候调用,以为着app可以和用户交互
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
//当app被销毁的时候调用
- (void)applicationWillTerminate:(UIApplication *)application {
}
//当app接受到内存警告的时候调用
-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
NSLog(@"%s, line = %d",__FUNCTION__,__LINE__);
}