【发布时间】:2019-06-26 18:33:46
【问题描述】:
我正在尝试将来自 AppDelegate 的 UIAlertController 中的 Push Notification(PN) 的消息呈现给当前的 ViewController。如果我发送 1 个没有问题的 PN 并显示警报!但是在单击警报中的“确定”按钮之前,我发送了第二个 PN,该消息未显示并收到以下警告消息:
"警告:尝试显示
已经呈现 "
那么我如何处理超过 1 个 PN 或者是否可以显示最后一个 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)
}
【问题讨论】:
标签: ios swift appdelegate