I thought this was simple: Whenever I get a remote notification while the app is running present a UIAlertController with the message.
The problem is that presenting that alert might happen just as the main app is about to push/present another view controller. In this case, I get ugly error messages like
pushViewController:animated: called on <UINavigationController 0x7f400c00> while an existing transition or presentation is occurring; the navigation stack will not be updated.
and the app might get into inconsistent states this way. How can I arrange view controller transitions such that they do not get in conflict like this?
Separating the controllers into two UIWindow
s solves this problem.
Instead of just presenting the alert on one of the app's view controllers you create a new window like this:
let screen = UIScreen.main
let screenBounds = screen.bounds
let alertWindow = UIWindow(frame: screenBounds)
alertWindow.windowLevel = UIWindowLevelAlert
let vc = UIViewController()
alertWindow.rootViewController = vc
alertWindow.screen = screen
alertWindow.isHidden = false
vc.present(alert, animated: true)
Now the view controllers in the app's main window can push and present other controllers simultaneously to showing alerts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With