警报视图自动关闭了Appdelegate中的ios13,并且在iOS11中工作正常,并且问题仅在iOS13上发生
let alertController = UIAlertController (title: "messageTitle", message:"notificationMessage", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "Close", style: .cancel, handler: nil)
alertController.addAction(cancelAction)
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindow.Level.alert + 1;
alertWindow.makeKeyAndVisible()
alertController.modalPresentationStyle = .fullScreen
alertWindow.rootViewController?.present(alertController, animated: true, completion: nil)
如果你创建新的UIWindow,你应该像一个属性一样保存它,因为"alertWindow"将在创建它的方法结束时被销毁。另一种情况是,您可以获取窗口guard let window = UIApplication.shared.keyWindow else { return }
并使用它。