Is there any way to check if iOS app is in background?

后端 未结 8 832
滥情空心
滥情空心 2020-12-04 10:38

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

In:

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


        
相关标签:
8条回答
  • 2020-12-04 11:14

    Swift version :

    let state = UIApplication.sharedApplication().applicationState
    if state == .Background {
        print("App in Background")
    }
    
    0 讨论(0)
  • 2020-12-04 11: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...

    0 讨论(0)
提交回复
热议问题