App called -statusBar or -statusBarWindow on UIApplication. Use the statusBarManager object on the window scene instead.

 


func setStatusBarBackgroundColor(color: UIColor) {

        guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

        statusBar.backgroundColor = color
    }

I run this code for status bar background color but at this time My application got crash show the issue in the output console.

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

'statusBar or -statusBarWindow' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene instead.


Unfortunately Apple deprecated some of the mentioned methods of accessing the status bar and editing its attributes. You will have to use the The StatusBarManager object of the WindowScene. The following method works for iOS 13 and above.

Use the following code:
if #available(iOS 13.0, *) {
            let statusBar = UIView(frame: UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
            statusBar.backgroundColor = UIColor.init(red: 237.0/255.0, green: 85.0/255.0, blue: 61.0/255.0, alpha: 1.0)
            UIApplication.shared.keyWindow?.addSubview(statusBar)
        } else {
             UIApplication.shared.statusBarView?.backgroundColor = UIColor.init(red: 237.0/255.0, green: 85.0/255.0, blue: 61.0/255.0, alpha: 1.0)
        }
        
to achieve this result:




Similar solutions you may also like...

Post a Comment

0 Comments