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


[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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM