statusBarFrame' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene instead iOS swift

 Problem:

I had a warning for my below code

        let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)

        statusBarView.backgroundColor = UIColor.red // Set your desired background color

        self.view.addSubview(statusBarView)


As like below


'statusBarFrame' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene instead.


How to solve that.


Solution:

After iOS 13 statusBarFrame was deprecated.So use the below code.

        if let windowScene = UIApplication.shared.connectedScenes.first asUIWindowScene {

            if let statusBarManager = windowScene.statusBarManager {

                let statusBarFrame = statusBarManager.statusBarFrame

                let statusBarView = UIView(frame: statusBarFrame)

                statusBarView.backgroundColor = UIColor.red

                self.view.addSubview(statusBarView)

            }

        }


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift