Good afternoon everyone, I have a problem with showing Alerts in iOS 13, my code is:
On AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Override point for customization after application launch.
debugPrint("didFinishLaunchingWithOptions")
let alert = UIAlertController(title: "My APP", message:"didFinishLaunchingWithOptions", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction!) in
debugPrint("OK")
}))
self.showAlertGlobally(alert)
return true
}
On Custom View Controller:
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view.
let alert = UIAlertController(title: "My App", message:"viewDidLoad", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction!) in
debugPrint("OK")
}))
self.showAlertGlobally(alert)
}
And my custom method:
func showAlertGlobally(_ alert: UIAlertController)
{
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.windowLevel = UIWindow.Level.alert
alertWindow.rootViewController = UIViewController()
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alert, animated: true, completion: nil)
}
it was working on iOS 12, the method was showing the Alert from the AppDelegate and any ViewController, but every UIAlertController disappear automatically before user responds since iOS 13
I tried this solutions:https://stackoverflow.com/questions/58131996/every-uialertcontroller-disappear-automatically-before-user-responds-since-ios and https://stackoverflow.com/questions/58148334/uialertcontroller-disappearing-since-ios-13, but still not working, if show the alert all view lose and disable the touch property in any item