您的位置:首页 > 移动开发 > IOS开发

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

2017-05-31 15:25 274 查看
[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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: