14
votes

I'm trying to build my app with Xcode 11 beta 6 and iOS 13 beta 8 but it throws this error once it starts to run:

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.'

What is the window scene and how do I use the statusBarManager?
And I'm not sure if this is relevant, but I'm not using any SwiftUI.

2
Are you changing status bar color or any property in your application?Manav
@Manav Yes, I change the alpha value on the status bar windowLukas Würzburger

2 Answers

10
votes

You need to add the following extension to access 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
    }
}
1
votes

To access StatusBar in Swift 5+ and iOS 13+

Need to replaced -satusBar or -statusWindow with statusBarManager.

if #available(iOS 13.0, *) {

        let statusBar = UIView(frame: UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
        statusBar.backgroundColor = .appNavigationThemeColor
          //  statusBar.tag = 100
        UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.addSubview(statusBar)

    } else {

            let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
            statusBar?.backgroundColor = .appNavigationThemeColor

        }
    }

Hope will be helping :)