I'm trying to present the message from a Push Notification(PN) in a UIAlertController from AppDelegate to the current ViewController. If I send 1 PN where is no problem and the alert is displayed! But then I send a second PN before I clicked on the OK button from the alert, the message is not displayed and get the following warning message:
"Warning: Attempt to present <UIAlertController> on <NavigationViewController> which is already presenting <UIAlertController>"
So how can I handle more than 1 PN or is it possible to show the last PN?
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
guard let aps = userInfo["aps"] as? [String: AnyObject] else {
completionHandler(.failed)
return
}
dump(aps)
let message = aps["alert"] as? String
let alertController = UIAlertController(title: "New message", message: message, preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(ok)
DispatchQueue.main.async {
self.window?.rootViewController?.presentedViewController?.present(alertController, animated: true, completion: nil)
}
completionHandler(UIBackgroundFetchResult.noData)
}