Is there any way to check if iOS app is in backgro

2019-01-16 08:28发布

I want to check if the app is running in the background.

In:

locationManagerDidUpdateLocation {
    if(app is runing in background){
        do this
    }
}

7条回答
劳资没心,怎么记你
2楼-- · 2019-01-16 09:21
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground || state == UIApplicationStateInactive)
{
   //Do checking here.
}

This may help you in solving your problem.

See comment below - inactive is a fairly special case, and can mean that the app is in the process of being launched into the foreground. That may or may not mean "background" to you depending on your goal...

查看更多
登录 后发表回答