gpt4 book ai didi

ios - 从 AppDelegate 到 PresentedViewController 的警报 : "Attempt to present UIAlertController on ... whitch is already presenting UIAlertController"

转载 作者:行者123 更新时间:2023-11-29 05:38:41 35 4
gpt4 key购买 nike

我正在尝试将 UIAlertController 中的推送通知(PN)中的消息从 AppDelegate 呈现到当前 ViewController。如果我发送 1 个 PN,没有问题,并且会显示警报!但是,在单击警报中的“确定”按钮之前,我发送了第二个 PN,该消息未显示并收到以下警告消息:

"Warning: Attempt to present <UIAlertController> on <NavigationViewController> which is already presenting <UIAlertController>"

那么我如何处理超过 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)
}

最佳答案

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

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

关于ios - 从 AppDelegate 到 PresentedViewController 的警报 : "Attempt to present UIAlertController on ... whitch is already presenting UIAlertController",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56779110/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com