推送通知:将设备令牌与设备相关联 [英] Push Notifications: Associating a device token with a device

查看:26
本文介绍了推送通知:将设备令牌与设备相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当发生此类情况时,我的应用程序当前正在接收与之前的应用程序用户帐户关联的推送通知:

My app is currently receiving push notifications that are associated with the previous application user account when this type of situation occurs:

  1. 玩家安装应用并注册为bob"
  2. bob 的设备令牌已注册到网络服务
  3. 玩家重新安装了应用并注册为phil"(在同一设备上)
  4. phil 的设备令牌已注册到网络服务

即使玩家现在以phil"的身份登录,他们仍会继续收到与bob"和phil"关联的帐户的推送通知.

Even though the player is now logged in as "phil" they will continue to receive push notifications for the account associated with "bob" as well as "phil".

如果我使用 UDID,我可以确保每个设备只注册一个设备令牌,因此从播放器的旧网络服务帐户bob"中删除 UDID 和设备令牌,从而确保每个设备只有一个活动帐户.当玩家注册为phil"并且网络服务器可以看到玩家使用相同的 UDID 注册了一个新帐户,然后从具有该 UDID 的任何旧帐户(即bob")中删除 UDID 和设备令牌时,就会发生这种情况.帐户).在有人再次登录该帐户(在同一设备上,或在新设备上)之前,不会再向 bob 帐户发送推送通知.

If I was using UDID I could ensure that only one device token is registered per device and therefore remove the UDID and device token from the player's old web service account, "bob", thus ensuring only one active account per device. This would happen when the player registers as "phil" and the web server could see that the player has registered a new account with the same UDID and then remove the UDID and device token from any old accounts with that UDID (i.e. the "bob" account). No more push notifications would be sent to the bob account until someone logs into that account again (on the same device, or a new one).

但是,这在使用 CFUDIDCreate 时效果不佳,因为它可能会在安装之间发生变化.

However, this is won't work very well when using CFUDIDCreate since it is likely to change between installs.

如何确保只收到当前登录用户的推送通知?或者,换句话说,我如何确保我的网络服务器只为每个设备存储一个设备令牌?

How do I ensure that push notifications are only received for the currently logged in user? Or, to put it another way, how do I ensure that my web server stores only one device token per device?

推荐答案

您可以使 APNS 令牌成为服务器端的密钥,而不是设备特定的标识符.重新安装应用时,您会将现有的(APNS 令牌,bob")记录替换为(APNS 令牌,phil"),从而在重新安装应用时移除令牌与 bob 帐户之间的链接.

You could make the APNS token the key server-side instead of a device specific identifier. When reinstalling the app, you would replace the existing (APNS token, "bob") record by (APNS token, "phil"), thus removing the link between the token and bob's account when reinstalling the app.

据我所知,APNS 令牌在应用程序的重新安装之间不会改变,所以这应该可以工作.(如果它确实在未来版本的 iOS 中重新安装之间发生了变化,这将不是问题,因为旧令牌不再有效,因此设备不会收到发送给 bob 的通知).

As far as I know the APNS token does not change between reinstalls of an app, so this should work. (If it did change between reinstalls in a future version of iOS, this would not be a problem because the old token would not be valid anymore, so the device would not get notifications sent to bob).

这篇关于推送通知:将设备令牌与设备相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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