Кажется, вам нужно держать объект UIWindow, пока вы не захотите показать предупреждение. Вот рабочий код с небольшими изменениями
private var win: UIWindow!
extension UIAlertController {
func show() {
win = UIWindow(frame: UIScreen.main.bounds)
let vc = UIViewController()
vc.view.backgroundColor = .clear
win.rootViewController = vc
win.windowLevel = .alert + 1
win.makeKeyAndVisible()
win.rootViewController?.present(self, animated: true, completion: nil)
}
open override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
win = nil
}
}
использование Используйте так же, как вы ранее использовали
let alertController = UIAlertController(title: newTitle, message: newMessage, preferredStyle: .alert)
let submit = UIAlertAction(title: submitTitle, style: .default) { (action) in
clickOK()
}
alertController.addAction(submit)
if let cancelTitle = cancelTitle, !cancelTitle.isEmpty {
let cancel = UIAlertAction(title: cancelTitle, style: .cancel) { (action) in
if let clickCancel = clickCancel {
clickCancel()
}
}
alertController.addAction(cancel)
}
alertController.show()