preferredStatusBarStyle not firing in iOS 13.4

Hi,

Just checking to see if I'm missing something. In iOS 13.3.1 preferredStatusBarStyle fired and worked fine. In iOS 13.4 and 13.4.1 is doesn't fire at all. I thought this was supposed to be fixed in iOS 13.4.1


I have themes set up in my app and they still work fine in iOS 13.3.1

override var preferredStatusBarStyle: UIStatusBarStyle
{
     // print("preferredStatusBarStyle fired")
     return Theme.current.barStyle
}
Answered by OOPer in 416100022

Seems the view hierarchy may be affecting.


Till now, I cannot reproduce the same issue with my simple sample code, which shows the same behavior both in 13.3 and 13.4.


Have you tried customizing the navigation controller?

For example, what happens if you replace the Custom Class of the navigation controller to this class?

class MyNavigationController: UINavigationController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        print(type(of: self), #function)
        let style = super.preferredStatusBarStyle
        print(type(of: self), style.rawValue)
        return style
    }
}

As far as tried in iOS 13.4 simulator, `preferredStatusBarStyle` is called.


Can you clarify on what condition it is not called? On actual devices? Some specific transitions? Or only your app?

Not fired.

Do you mean that if you uncomment the print, it does not print ?


If it worked in 13.3, it is not a dark mode issue.

nevertheless, may look at this, at least for a fix:

https://stackoverflow.com/questions/58203902/preferredstatusbarstyle-not-respecting-on-ios-13

Yes. If I uncomment the print statment it does not print in iOS 13.4 and 13.4.1


If I load the same app into xcode 11.3.1, iOS 13.3.1, the print statment runs. This is on either my iPhone 6s or iPhone XSMax or the sim.

If I load the same app into xcode 11.3.1, iOS 13.3.1, the print statment runs. This is on either my iPhone 6s or iPhone XSMax or the sim. I haven't tried to test this on anything but my app. I'll create a quick test app and see.

So I created a test app in xcode 11.4.1

Ran it and the print statement fired.


Then I ran it in xcode 13.3.1

The print statement fired.


Then I embedded the view in a navigationColtroller

Then I ran it in xcode 13.3.1

The print statement did not fire.


Then I ran it in xcode 13.4.1

The print statement did not fire.


Then I deleted navigationColtroller

Then I ran it in xcode 13.3.1

The print statement fired.


Then I ran it in xcode 13.4.1

The print statement fired.


It's the same in the sim or device.


override var preferredStatusBarStyle: UIStatusBarStyle
    {
        print("preferredStatusBarStyle fired")
        return .lightContent
    }

Thanks for showing the result with your test app.


But the result shows no difference between iOS 13.3.1 and 13.14.1:

- When embedded in a navigationController, the print statement is not executed.

- When not embedded in a navigationController, the print statement is executed.


Do you notice what is the different between your app and your test app?

So far I am still trying to figure this out. My app has 51 views and one navigation controller linked to the first view. I tried updating the cocoa pods. I've looked at everywhere in my app that I set the preferredStatusBarStyle. There doesn't seem to be a correlation. It still works fine on Xcode 11.3.1 but preferredStatusBarStyle doesn't fire on 11.4 or 11.4.1


I have a theme protocol and three themes following it (lite, grey and dark). The themes set the preferredStatusBarStyle to .default or .lightContent


This is from the LiteTheme


var barStyle: UIStatusBarStyle = .default


This is in every viewController


    override var preferredStatusBarStyle: UIStatusBarStyle
    {
        return Theme.current.barStyle
    }
Accepted Answer

Seems the view hierarchy may be affecting.


Till now, I cannot reproduce the same issue with my simple sample code, which shows the same behavior both in 13.3 and 13.4.


Have you tried customizing the navigation controller?

For example, what happens if you replace the Custom Class of the navigation controller to this class?

class MyNavigationController: UINavigationController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        print(type(of: self), #function)
        let style = super.preferredStatusBarStyle
        print(type(of: self), style.rawValue)
        return style
    }
}

That worked!


class MyNavigationController: UINavigationController
{
   
    override func viewDidLoad()
    {
        super.viewDidLoad()
       
        // Do any additional setup after loading the view.
    }
   
    override var preferredStatusBarStyle: UIStatusBarStyle
    {
        return Theme.current.barStyle
    }
}
preferredStatusBarStyle not firing in iOS 13.4
 
 
Q