0

I have added the second window in my app for presenting the specific controller when user taps the remote push notification.

func navigateThroughPushnotification(controller: UINavigationController) {
    let window = UIWindow(frame: UIScreen.main.bounds)
    let vc = UIViewController()
    vc.view.backgroundColor = .clear
    window.rootViewController = vc
    window.windowLevel = UIWindow.Level.alert + 1
    window.makeKeyAndVisible()
    if let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView {
        statusBar.backgroundColor = kAppDefaultColor
    }
    vc.present(controller, animated: true, completion: nil)
}

Problem is that I want to change the status bar color of this window also but the code which I have used to change the color of my main window doesn't work this time.

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

Now this code works very well for the main window. Please someone help to detect what should be done to change the color of the second window. Thanks in advance

1 Answers1

0

This is Used for only iOS 7 and higher version

First of all go to your application's Info.plist, set View controller-based status bar appearance to YES.

after override preferredStatusBarStyle in each of your view controllers.

eg:

override var preferredStatusBarStyle: UIStatusBarStyle {     
      return .lightContent
}

If you have preferredStatusBarStyle returning a different preferred status bar style based on something that changes inside of your view controller, then you want to call setNeedsStatusBarAppearanceUpdate() on state changes.

Bhumesh Purohit
  • 491
  • 1
  • 8
  • 26
  • I have done everything . i.e defined the key in info.plist and is working fine for initial Window . But when I Defined another upon receiving the push in that case this is not working – VIJAY SINGH RAGHAV Oct 17 '19 at 11:37