When app is moving from background to foreground (detecting via a notification) - it reads the wrong self.traitCollection.userInterfaceStyle i.e. when I change to dark/light when app is in background - what am I doing wrong or not doing at all?
private var observer: NSObjectProtocol?
override func viewDidLoad() {
super.viewDidLoad()
self.observer = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: .main) { [unowned self] _ in
self.configureNavbar()
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.configureNavbar()
}
func configureNavbar() {
if #available(iOS 12.0, *) {
if self.traitCollection.userInterfaceStyle == .dark {
self.navigationController?.navigationBar.barTintColor = .black
} else {
self.navigationController?.navigationBar.barTintColor = .white
}
}
}