例如:
在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 UIKitclass 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: falsevIEwWillAppear active: falsevIEwDIDAppear active: true // This differs from 11vIEwDIDAppear with delay active: true
在iOS 11上运行时:
vIEwDIDLoad() active: falsevIEwWillAppear active: falsevIEwDIDAppear active: falsevIEwDIDAppear with delay active: true
我无法告诉你这是否有意,但事情确实发生了变化.也许在它上面写一个雷达?
总结以上是内存溢出为你收集整理的为什么在iOS 11中,我的UIApplicationState显示为非活动状态而不是活动状态?全部内容,希望文章能够帮你解决为什么在iOS 11中,我的UIApplicationState显示为非活动状态而不是活动状态?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)