美文网首页OC基础原理
iOS之应用程序状态UIApplicationState

iOS之应用程序状态UIApplicationState

作者: KODIE | 来源:发表于2017-05-16 11:24 被阅读0次

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

    typedef enum UIApplicationState : NSInteger {
        UIApplicationStateActive,
        UIApplicationStateInactive,
        UIApplicationStateBackground
    } UIApplicationState;
    
    • UIApplicationStateActive
    The app is running in the foreground and currently receiving events.
    应用程序运行在前台,目前接收事件。
    
    • UIApplicationStateInactive
    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>从后台进入前台的过度时间

    • UIApplicationStateBackground
    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...
        }
    
    

    相关文章

      网友评论

        本文标题:iOS之应用程序状态UIApplicationState

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