Is there a way how to set the default status bar style while keeping the UIViewControllerBasedStatusBarAppearance enabled?
Here is the problem, I'm dealing with:
Nearly the whole app needs to be using UIStatusBarStyle.LightContent as the navigation bar has a dark background. Originally, UIViewControllerBasedStatusBarAppearance was disabled and the following was set in in Info.plist for while text status status bar:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
This worked just fine until I found out that this .LightContent status bar is shown even for some of the share extensions, like Facebook Messenger, causing it to be unreadable:
This could be solved by using UIViewControllerBasedStatusBarAppearance, but then I would need to add the following method to all of view controllers which I want to avoid as the app is quite large.
Moreover, for the one screen in the app that has light nav bar background, I was switching to dark nav bar using UIApplication.sharedApplication().setStatusBarStyle() but this method in deprecated in iOS 9.
Any ideas how to solve this? Swizzling?

Solution
The easiest and cleanest way how to achieve that is to add the following line in
AppDelegate'sapplication:willFinishLaunchingWithOptionsmethod:This will make
.LightContentas the default status bar style thorough the app as long as your app usesUINavigationController.Don't forget to keep the following setting in app's
Info.plistif want to use.LightContentstatus bar style during launch for splash screen:TL;DR
My current setup, which is very similar to many other apps, uses
UITabBarControlleras the top most controller withUINavigationControllerstack for each tab.UINavigationControllertakes care of the status bar style (as it should) and do not callpreferredStatusBarStyle()on its child view controllers. Therefore, implementing the subclassing solution proposed by par does not work in my case.Further subclassing the custom subclass of
UINavigationControllerI'm using would not be a clean solution either.Now, since the app has
UIViewControllerBasedStatusBarAppearanceenabled and correct status bar style everywhere in the app itself,SFSafariViewControllerand share extension like Messages, Mail, etc use the correct (.Default) status bar style too.The only exception where the correct status bar style is not used is the Facebook Messenger's share extension mentioned in the question. However, it seems to be a bug in the extension itself as all apps I have tried that use
.LightContentstatus bar style (like Twitter, for example) have the same issue - presented FB Messenger share extension from the app has a status bar with white color text.