[英]disable receive push from didReceive in NotificationService
我想在特殊情況下禁用向用戶發送推送通知。 我將第一個Push保存在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")
}
}
}
}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.