0

该项目(react-native)在 ​​Xcode 10.2 上运行良好,为了在 iOS 13 上对其进行测试,我尝试使用 Xcode 11.2.1 打开项目,应用程序在启动时崩溃,来自 Xcode 11.2.1 控制台的错误如下:

Assertion failure in -[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3900.12.16/UIApplication.m:5316
2019-12-10 14:26:37.206842+0530 workish[73259:574909] *** 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.'
*** First throw call stack:
4

1 回答 1

2

您正在尝试访问自 iOS 13 以来已弃用的代码中某处的 statusBar。下面是获取 iOS 13+ 及以下版本的 statusBar 的示例代码

  if #available(iOS 13.0, *) {
    let statusBarFrame = UIView(frame: UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
     statusBarFrame.backgroundColor = UIColor.init(red: 243/250, green: 243/250, blue: 243/250, alpha: 1)
     UIApplication.shared.keyWindow?.addSubview(statusBarFrame)
} else {
     UIApplication.shared.statusBarView?.backgroundColor = UIColor.init(red: 243/250, green: 243/250, blue: 243/250, alpha: 1)
}
于 2019-12-10T09:26:18.383 回答