为什么在iOS 11中,我的UIApplicationState显示为非活动状态而不是活动状态?

我已经更新到最新的xcode – 9和iOS 11,现在我在UIApplicationState面临问题.任何人都可以告诉我为什么苹果在ApplicationState中做了这个改变.

例如:
   在viewController viewWillAppear期间,我正在检查UIApplicationState:

     UIApplicationState applicationState = [UIApplication sharedApplication].applicationState;
        if (applicationState == UIApplicationStateActive)
        {
        }

但我得到applicationState = UIApplicationStateInactive.

或者我需要通过额外代码单独处理iOS 11版本:

  if (applicationState == UIApplicationStateActive || (@available(iOS 11, *) && applicationState == UIApplicationStateInactive)){
}

在所有版本中保持应用程序状态的任何其他答案?

提前致谢,

最佳答案
**更新的答案**

我使用以下代码来测试iOS 10和iOS 11设备上的状态.

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        print("\(#function) active: \(UIApplication.shared.applicationState == .active)")
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("\(#function) active: \(UIApplication.shared.applicationState == .active)")
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("\(#function) active: \(UIApplication.shared.applicationState == .active)")

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
            print("\(#function) with delay active: \(UIApplication.shared.applicationState == .active)")
        }
    }
}

在iOS 10上运行时:

viewDidLoad() active: false
viewWillAppear active: false
viewDidAppear active: true // This differs from 11
viewDidAppear with delay active: true

在iOS 11上运行时:

viewDidLoad() active: false
viewWillAppear active: false
viewDidAppear active: false
viewDidAppear with delay active: true

我无法告诉你这是否有意,但事情确实发生了变化.也许在它上面写一个雷达?

转载注明原文:为什么在iOS 11中,我的UIApplicationState显示为非活动状态而不是活动状态? - 代码日志