【问题标题】:Alert from AppDelegate to PresentedViewController: "Attempt to present UIAlertController on ... whitch is already presenting UIAlertController"从 AppDelegate 到 PresentedViewController 的警报:“尝试在...上呈现 UIAlertController 已经在呈现 UIAlertController”
【发布时间】: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


    【解决方案1】:

    您可以管理通知列表/堆栈并连续显示它们,直到您的列表/堆栈为空。

    查看此答案以了解如何显示多个警报:Attempt to present UIAlertController on View Controller which is already presenting (null) [Swift]

    【讨论】:

      猜你喜欢
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多