gpt4 book ai didi

ios - 在 NotificationService 中禁用从 didReceive 接收推送

转载 作者:行者123 更新时间:2023-11-28 23:32:06 24 4
gpt4 key购买 nike

我想禁用在特殊情况下向用户发送推送通知。我在 userDefault 中保存了我的第一个推送,在第二个中我检查它是否相同。当我调试它时输入返回而不是继续,但我仍然收到推送通知。从 firebase api 发送的推送

 override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {

if let dict = request.content.userInfo["aps"] as? Dictionary<AnyHashable, AnyHashable> {
if let did = dict["did"] as? String {
if let message = dict["message"] as? String {
let currentPush = did + "_" + message

if let lastPush = UserDefaults.standard.string(forKey: "lastPush"), currentPush == lastPush {
print("enter")
return
}
else {
UserDefaults.standard.setValue(currentPush, forKey: "lastPush")
}
}
}
}}

最佳答案

与 Android 不同,开发者有 some control是否显示通知,iOS 不提供该功能。发送的通知将始终显示。因此,您的 return 将不起作用。

您可以做的一个解决方法是发送 silent push notification ,处理数据,如果它符合您的逻辑,则创建本地通知并显示该通知。

关于ios - 在 NotificationService 中禁用从 didReceive 接收推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100030/

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