我认为这很简单: 每当我在应用程序运行时收到远程通知时,都会向 UIAlertController 显示消息。
问题在于,当主应用程序即将推送/显示另一个 View Controller 时,可能会显示该警报。在这种情况下,我会收到丑陋的错误消息,例如
pushViewController:animated: called on <UINavigationController 0x7f400c00> while an existing transition or presentation is occurring; the navigation stack will not be updated.
应用程序可能会以这种方式进入不一致的状态。 我怎样才能安排 View Controller 转换,使它们不会像这样发生冲突?
最佳答案
将 Controller 分成两个 UIWindow
可以解决这个问题。
您可以像这样创建一个新窗口,而不是仅仅在应用程序的 View Controller 之一上显示警报:
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)
现在应用程序主窗口中的 View Controller 可以同时推送和呈现其他 Controller 以显示警报。
关于iOS:WAITING现有的过渡或演示完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43780731/