美文网首页
iOS 程序运行状态UIApplicationState

iOS 程序运行状态UIApplicationState

作者: 清风_____ | 来源:发表于2021-02-02 10:01 被阅读0次

一、应用程序状态枚举 UIApplicationState:

typedef NS_ENUM(NSInteger, UIApplicationState) {
UIApplicationStateActive, //(前台)
UIApplicationStateInactive, //(收到通知)
UIApplicationStateBackground //(后台)
} API_AVAILABLE(ios(4.0));

UIApplicationStateActive :应用程序运行在前台,目前接收事件。

UIApplicationStateInactive:应用程序运行在前台但不接收事件。这可能发生的由于一个中断或因为应用过渡到后台或者从后台过度到前台。
<1>电话进来或者其他中断事件
<2>从前台进入后台的过度事件
<3>从后台进入前台的过度事件

UIApplicationStateBackground :应用程序在后台运行

二、获取状态代码:

1、全局获取方式

UIApplicationState state = [UIApplication sharedApplication].applicationState;
    if(state == UIApplicationStateActive){
        //code here...
    }else if(state == UIApplicationStateBackground){
        //code here...
    }else{
        //code here...
    }

2、应用生命周期中获取
AppDelegate.m

- (void)applicationWillResignActive:(UIApplication *)application {
    UIApplicationState state =  application.applicationState;
    if(state == UIApplicationStateActive){
        //code here...
    }else if(state == UIApplicationStateBackground){
        //code here...
    }else{
        //code here...
    }
}

https://www.cnblogs.com/zxs-19920314/p/iOSUIApplicationState.html

相关文章

网友评论

      本文标题:iOS 程序运行状态UIApplicationState

      本文链接:https://www.haomeiwen.com/subject/jdgetltx.html