ios - UIApplication 上名为 -statusBar 或 -statusBarWindow 的应用程序

标签 ios swift uiwindow uistatusbar ios13

我正在尝试使用 Xcode 11 beta 6 和 iOS 13 beta 8 构建我的应用程序,但一旦开始运行就会抛出此错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'

什么是窗口场景以及如何使用 statusBarManager
我不确定这是否相关,但我没有使用任何 SwiftUI

最佳答案

您需要添加以下扩展才能访问 statusbarview :

extension UIApplication {
    var statusBarUIView: UIView? {
        if #available(iOS 13.0, *) {
            let tag = 38482458385
            if let statusBar = self.keyWindow?.viewWithTag(tag) {
                return statusBar
            } else {
                let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
                statusBarView.tag = tag

                self.keyWindow?.addSubview(statusBarView)
                return statusBarView
            }
        } else {
            if responds(to: Selector(("statusBar"))) {
                return value(forKey: "statusBar") as? UIView
            }
        }
        return nil
    }
}

关于ios - UIApplication 上名为 -statusBar 或 -statusBarWindow 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57801484/

相关文章:

ios - keyWindow = nil 仅在 iPad 上

iphone - 如何删除 UIWindow?

ios - AES 加密/解密 iOs 和 .Net

ios - UITableView Header 上的自动布局

ios - 如何在 UIWebView 之上覆盖 UIButton(关闭)按钮?

ios - Vapor 解释代码有困难,执行时出现401错误

xcode6 - ios7.1 上的 UIWindow 布局问题与 xcode 6.0

ios - 如何在 ios 中捕获数据库异常?

ios - Xcode 7 用户界面测试 : Dismiss Push and Location alerts

javascript - 如何从 Swift 调用 jquery 函数?