应用程序更新后推送通知令牌是否会更改?

Does push notification token changes after application update?

我问的是两种情况:

1) 在我们从 App Store 进行定期更新后

2) 在我们模拟更新后,通过从应用商店下载当前版本并从 Xcode 安装并 运行安装新版本,

推送通知令牌有变化吗?如果发生变化,多久发生一次。每次,还是时不时?

我问这个,因为我正在做一些测试,我想在更新后保留 Documents 文件夹。因此,这可以像我上面描述的那样轻松完成,方法是从商店下载应用程序,然后 运行 从 Xcode 中安装一个新版本。但是,我注意到推送通知停止工作了。然后我重复了这几次(卸载应用程序,从商店安装它,然后 运行 来自 Xcode 的升级版本)并且每次推送通知都有效。

我想知道这是否是由于推送通知令牌更改所致?

据我所知,

1) App Store 的定期更新 - APNS 令牌不会更改。

2) 这有点棘手。我相信象征性的变化。首先,我想让您知道应用商店版本使用 APNS 生产证书,而来自 xcode 的构建 运行 使用开发证书。它将生成不同的令牌。如果您仍然向 apple 推送生产服务器发送推送通知,您将不会在 xcode 版本上收到它们。您需要将它们发送到 apple push 沙箱服务器。

Apple Docs:

Never cache device tokens; always get them from the system when you need them. Although device tokens are unique to an app and device, they can change over time. The device token can change at any time but is guaranteed to be different when the user restores their device from a backup, when the user installs your app on a new device, and when the user reinstalls the operating system. Fetching the token from the system ensures that you always have the current token needed to communicate with APNs. In addition, if the token has not changed, fetching it is fast and does not incur any significant overhead.

因此,根据 Apple 文档,它至少更改了 3 个地方:

  • 从备份恢复
  • 在新设备上安装
  • 正在重新安装 OS

所以典型的更新不会改变它们。我不记得自己必须同意在更新后接收...

重要提示:

如果用户注销应用程序而新用户登录同一设备,则令牌将保持不变。为什么?因为没有 class 或消息系统向开发人员公开让 OS 知道它必须从设备注销令牌。

因此您必须从那个 user/account 取消注册该令牌,即您必须通过某种网络呼叫您到您的平台,否则新用户将收到属于以前用户的推送通知。