为什么在iOS 11中,我的uiapplicationstate显示为无活跃的状态而不是活动



我已更新为最新的Xcode -9和iOS 11,现在我在UiapplicationState中面临问题。谁能告诉我苹果为什么在应用程序处进行了此更改。

例如: 在ViewController ViewWillAppear期间,我正在检查UiapplicationState:

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

但是我正在获取应用程序= 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

我不能告诉你这是否是故意的,但是肯定有所改变。也许在上面提交雷达?

相关内容

  • 没有找到相关文章

最新更新