获取APP活跃状态代码如下:
UIApplicationState state = [UIApplication sharedApplication].applicationState;
if (state == UIApplicationStateActive){
NSLog(@"前台活跃状态");
}else if(state == UIApplicationStateInactive) {
NSLog(@"不活跃状态");
}else if(state == UIApplicationStateBackground) {
NSLog(@"后台状态");
}
由系统枚举可知苹果官方给我们定义三种状态:
typedef NS_ENUM(NSInteger, UIApplicationState) {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} API_AVAILABLE(ios(4.0));
UIApplicationStateActive
当前APP处于前台运行。
UIApplicationStateInactive
下拉(iPhone X左上角下拉)状态栏,查看通知消息
上拉(iPhone X右上角下拉)查看快捷键
双击home键,弹出运行中任务栏
应用内拨打电话
UIApplicationStateBackground
当前APP处于后台运行。
网友评论