iOS开发_判断应用在前台还是后台

1、UIApplicationState 枚举判断应用的状态

typedef NS_ENUM(NSInteger, UIApplicationState) {
UIApplicationStateActive, // 应用处于活跃状态
UIApplicationStateInactive, // 应用处于非活跃状态
UIApplicationStateBackground // 应用处于后台
} NS_ENUM_AVAILABLE_IOS(4_0);

2、实例代码

UIApplicationState state = [UIApplication sharedApplication].applicationState;
if (state != UIApplicationStateBackground) {
    CHLog(@"应用在前台")
}
posted @ 2021-11-15 17:30  CH520  阅读(289)  评论(0编辑  收藏  举报