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

后端 未结 8 964
滥情空心
滥情空心 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:06

    swift 5

    let state = UIApplication.shared.applicationState
        if state == .background {
            print("App in Background")
            //MARK: - if you want to perform come action when app in background this will execute 
            //Handel you code here
        }
        else if state == .foreground{
            //MARK: - if you want to perform come action when app in foreground this will execute 
            //Handel you code here
        }
    

提交回复
热议问题