[英]disable receive push from didReceive in NotificationService
I want to disable send push notification to user under special conditions. 我想在特殊情况下禁用向用户发送推送通知。 I saved my first Push in userDefault and in the second I check if it's the same. 我将第一个Push保存在userDefault中,然后在第二个中检查是否相同。 when i debug it enter to return and not continue, but still i get a push notification. 当我调试它进入返回而不是继续,但仍然我得到一个推送通知。 the push sent from firebase api 从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")
}
}
}
}}
Unlike Android where the developer has some control whether to show the notification or not, iOS does not provide that facility. 与Android(开发人员可以控制是否显示通知)不同,iOS不提供该功能。 A notification sent will always be shown. 发送的通知将始终显示。 So, your return
won't work. 因此,您的return
将无效。
One work around that you can do is send a silent push notification , process the data and if it fits your logic, then create a local notification and show that. 您可以采取的一种解决方法是发送一个静默推送通知 ,处理数据,如果数据符合您的逻辑,则创建一个本地通知并显示该通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.