如何管理 iOS apns 令牌更改 [英] How to manage iOS apns token changes

查看:23
本文介绍了如何管理 iOS apns 令牌更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,即用户在卸载并重新安装我的应用程序后开始收到双重通知,因为设备向我的服务器发送了 2 个不同的 APNS 令牌 - 一个来自第一次安装,另一个在重新安装应用程序后.由于令牌不同,我无法确定这是同一台设备.

I had an issue where a user started receiving double notifications after uninstalling and reinstalling my app, as the device sent to my server 2 different APNS tokens - one from the first installation and the other after reinstalling the app. Since the tokens were different I could not know this is the same device.

直到iOS 9出来,我每次卸载和重新安装应用程序,我总是得到相同的APNS,所以很容易知道这是用户和以前使用的相同设备.从 iOS 9 开始,似乎每次安装都会更改 APNS 令牌.

Until iOS 9 came out, every time I uninstalled and reinstalled the app, I always got the same APNS, so it was easy to know that this is the same device the user used as before. Since iOS 9, it seems that the APNS token is changed on every installation.

我的问题是如何判断客户端是否卸载并重新安装应用程序,并更新其 APNS 令牌而不是添加新令牌?

My question is how to tell if a client uninstall and reinstall the app, and update his APNS token instead of adding a new token?

我问这个问题,因为这听起来像是大多数 iOS 开发人员必须处理的事情,但我找不到 Apple 提供的任何最佳实践来解决这个问题,所以我希望其他人可以分享他们在这个问题上的经验.

I am asking as this sounds to me like something most iOS developers had to handle, but I couldn't find any best practice from Apple on how to tackle this, so I hoped that other can share their experience with this issue.

推荐答案

我们最终是这样解决的:

This is how we ended up solving it:

在每次应用启动时:

  1. 创建推送通知令牌
  2. localstorage 中有令牌吗?
    • yes - 将令牌与本地存储进行比较.它们相同吗?
      • 是 - 返回
      • 否 - 使用新令牌更新服务器,并在服务器响应OK"后将其保存在本地存储和钥匙串中
  • yes - 将令牌与钥匙串进行比较.它们相同吗?
    • 是 - 将令牌保存在 localstorage 中并返回
    • 否 - 使用新令牌更新服务器,并在服务器响应OK"后将其保存在本地本地
      存储和钥匙串

    如果有人有更优雅的方法来解决它,我很乐意听到它

    If anyone has a more elegant way to solve it I would love to hear about it

    这篇关于如何管理 iOS apns 令牌更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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