美文网首页
iOS判断程序在前台还是后台

iOS判断程序在前台还是后台

作者: LeeRich | 来源:发表于2017-12-29 10:02 被阅读15次
[UIApplication sharedApplication].applicationState will return current state, check it possible values and don’t create unnecessary flags when you can use system features.

Values you may want to consider:

UIApplicationStateActive(前台)
UIApplicationStateInactive(收到通知)
UIApplicationStateBackground(后台)

e.g.

+(BOOL) runningInBackground
{
    UIApplicationState state = [UIApplication sharedApplication].applicationState;
    BOOL result = (state == UIApplicationStateBackground);

    return result;
}

+(BOOL) runningInForeground
{
    UIApplicationState state = [UIApplication sharedApplication].applicationState;
    BOOL result = (state == UIApplicationStateActive);

    return result;
}

相关文章

网友评论

      本文标题:iOS判断程序在前台还是后台

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