ios - 在 NotificationService 中禁用从 didReceive 接收推送
问题描述
我想在特殊情况下禁用向用户发送推送通知。我将我的第一个 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")
}
}
}
}}
解决方案
推荐阅读
- c++ - 为什么在 ctor 中不允许访问成员对象的成员?
- java - 获取图像中每个字母的矩形边界
- c# - 根据 Unity 中的目标距离更改弹丸的速度
- javascript - 为什么我的 JavaScript/JQuery 添加和删除带有函数的类不起作用?
- node.js - NPM - 使用 React 构建的网站无法构建
- ruby - 参数数量错误(给定 3,预期 1..2)
- python - 如何使用 python 的“types”关键字过滤来自 Google Places API 的 json 数据
- elasticsearch - Fluent Bit Filter 将 Unix Epoch 时间戳转换为人类可读的时间格式
- php - 自定义 PHP 狙击程序,用于向管理员发送电子邮件通知,以了解 WooCommerce 中的待处理订单状态,从而导致处理订单的电子邮件重复
- google-maps - Google Maps SDK for Unity 在特定区域不起作用