[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;
}
posted on 2017-05-31 15:25  ZOYOO  阅读(1884)  评论(0编辑  收藏  举报