如果 APNS 设备令牌过期,会发生什么? [英] What Happen If a APNS Device Token Expired?

查看:37
本文介绍了如果 APNS 设备令牌过期,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此论坛帖子 APNS 设备令牌是否会改变,一旦创建? 设备令牌可能已过期,或者 APNS 可能会更改设备令牌.我的问题是,如果服务器将此过期令牌发送给 Apple,APNS 是否会使用过期令牌进行通知?APNS 可以将此过期令牌用于其他设备吗?

According to this forum post Does the APNS device token ever change, once created? The device token might be expire or APNS might change the device token. My question is that whether the APNS will use the expired token for notification if the server send this expired token to Apple? Can APNS use this expired token for another device?

推荐答案

我从来没有遇到过过期的设备令牌,所以我不能从我的个人经历中告诉你.我也不能从 Apple 的 APNS 文档中告诉你,因为他们没有回答你的问题(我不止一次阅读了他们所有的 APNS 文档).

I've never encountered an expired device token, so I can't tell you from my personal experience. Nor can I tell you from Apple's APNS documentation, because they don't answer your question (and I read all their APNS docs more than once).

无论您的问题的答案是什么,您的应用和服务器都应该能够处理设备令牌过期问题.

Your app and your server should be able to handle device token expiration regardless to what the answer to your question is.

  1. 始终在您的应用启动时调用 registerForRemoteNotificationTypes,如果设备令牌与您的应用在该设备上获得的最后一个设备令牌不同,则将设备令牌发送到服务器.

  1. Always call registerForRemoteNotificationTypes when your app is launched, and send the device token to the server if it's different than the last device token your app got on that device.

在您的服务器中为使用您的应用的每台设备分配另一个唯一标识符.让应用程序将该标识符与设备令牌一起发送到您的服务器.这样,如果设备令牌发生变化,您的服务器就会知道它是现有设备的新设备令牌,而不是安装了您的应用的新设备.

Assign in your server another unique identifier for each device that uses your app. Have the app send that identifier to your server along with the device token. This way, if the device token changes, your server will know it's a new device token for an existing device and not a new device where your app was installed.

遵循 #1 和 #2 将确保您的服务器将拥有最近启动您的应用程序的每台设备的当前设备令牌(在您的应用程序最近未启动的设备上,用户可能没有)我不太关心你的应用,所以我不确定向他们发送推送通知会有什么不同).

Following #1 and #2 will ensure that your server will have the current device token for each device on which your app was launched recently (on devices where your app wasn't launched recently, the users probably don't care much about your app, so I'm not sure that sending them push notifications will make any difference).

如果您确实向旧设备令牌发送通知,如果它有效,则一切正常.如果没有,您将收到无效令牌错误响应,或者您将在反馈服务中获得该设备令牌.在这两种情况中的任何一种情况下,您都应该停止向该令牌发送通知.

If you do send a notification to an old device token, if it works, all is good. If it doesn't, you'd either get an Invalid Token error response or you'd get that device token in the Feedback service. In either of those two cases, you should stop sending notifications to that token.

我假设 APNS 不会为其他设备重用过期的令牌,但如果确实如此,您的服务器可以使用我在 #2 中建议的唯一标识符来识别它.在这种情况下,请确保您的服务器仅将设备令牌分配给其他设备.

I assume APNS won't reuse an expired token for another device, but if it does, your server can identify it by using the unique identifier I suggested in #2. In that case, make sure your server assigns the device token only to the other device.

这篇关于如果 APNS 设备令牌过期,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆