Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App called -statusBar or -statusBarWindow on UIApplication

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.

like image 896
Lukas Würzburger Avatar asked Sep 05 '19 08:09

Lukas Würzburger


People also ask

What is a UIApplication?

The centralized point of control and coordination for apps running in iOS. Every iOS app has exactly one instance of UIApplication (or, very rarely, a subclass of UIApplication ). When an app launches, the system calls the UIApplicationMain (_:_:_:_:) function.

How do I access the UIApplication object in iOS?

Every iOS app has exactly one instance of UIApplication (or, very rarely, a subclass of UIApplication). When an app is launched, the system calls the UIApplicationMain(_:_:_:_:) function; among its other tasks, this function creates a Singleton UIApplication object. Thereafter you access the object by calling the shared class method.

What is the UIApplicationMain function in Android?

When an app launches, the system calls the UIApplicationMain (_:_:_:_:) function. Among its other tasks, this function creates a singleton UIApplication object that you access using shared. Your app’s application object handles the initial routing of incoming user events.

How many instances of UIApplication are in an iOS app?

Every iOS app has exactly one instance of UIApplication (or, very rarely, a subclass of UIApplication ). When an app launches, the system calls the UIApplicationMain (_:_:_:_:) function. Among its other tasks, this function creates a singleton UIApplication object that you access using shared.


1 Answers

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
    }
}
like image 113
Manav Avatar answered Nov 02 '22 05:11

Manav