Reputation: 208
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. when i debug it enter to return and not continue, but still i get a push notification. the push sent from 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")
}
}
}
}}
Upvotes: 0
Views: 261
Reputation: 2582
Unlike Android where the developer has some control whether to show the notification or not, iOS does not provide that facility. A notification sent will always be shown. So, your return
won't work.
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.
Upvotes: 1