在集成到我的应用程序之前,我正在测试 Apple 推送通知服务(沙盒模式)。我们可能会以每分钟数千次的数量级发送推送通知 - 因此主要要求之一是如果应用程序被删除(或重新安装),则不向无效(已删除)设备 token 发送通知。
设备 token ,接收于:
application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
在特定的应用程序安装中。新安装会创建一个新 token ,而之前的 token 将失效。
根据 Apple's APNS document ,发送过期设备 token 的请求应该返回:
410 The device token is no longer active for the topic.
但是,对于有效和过期的设备 token ,我始终获得 200。正确设备 token 的通知会发送到设备,而无效(过期) token 的通知则不会。
我正在使用,npm apn在服务器端打包并在运行 iOS 12.3 的设备上进行测试。
我是不是漏掉了什么?
最佳答案
我也注意到了这一点。对于无效/过期的 token ,我通常会收到 200 响应代码和以下正文:
{
"multicast_id": 7942205170696355362,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
我假设您必须解析响应正文并检查成功或失败计数以确定通知是否实际送达。 如果失败,则从您的数据库(或您存储要发送的 token 的任何位置)中删除此 token ,这样它就不会尝试再次将其发送到相同的 token 。
关于ios - APNS 服务为过期的设备 token 发送 200?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56606381/