OC基础原理

iOS之应用程序状态UIApplicationState

2017-05-16  本文已影响0人  KODIE

应用程序状态有三个,是一个枚举:

typedef enum UIApplicationState : NSInteger {
    UIApplicationStateActive,
    UIApplicationStateInactive,
    UIApplicationStateBackground
} UIApplicationState;
The app is running in the foreground and currently receiving events.
应用程序运行在前台,目前接收事件。
The app is running in the foreground but is not receiving events. This might happen as a result of an interruption or because the app is transitioning to or from the background.
应用程序运行在前台但不接收事件。这可能发生的由于一个中断或因为应用过渡到后台或者从后台过度到前台。

三个场景:
1>电话进来或者其他中断事件
2>从前台进入后台的过度时间
3>从后台进入前台的过度时间

The app is running in the background.
应用程序在后台运行。

代码如下:

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

上一篇下一篇

猜你喜欢

热点阅读