什么情况会触发 Firebase 推送令牌刷新?

What situations trigger Firebase push token refresh?

所以我遇到推送令牌在使用 firestore 和云消息传递的 react-native 项目中变得无效。我只是好奇是什么触发了推送令牌更改。我注意到一对夫妇:

只是想知道是否有人可以提供导致生成新令牌和旧令牌过期的事物的明确列表。不确定这是否也是时间的函数,在测试中还没有走那么远。

需要说明的是,我指的不是访问令牌。这是关于 firebase 云消息令牌

可以在 messaging/registration-token-not-registered 错误代码下的 documentation for the Firebase Admin SDK 中查看可能原因的列表:

  • The client app unregistered itself from FCM.
  • The client app was automatically unregistered. This can happen if the user uninstalls the application or, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
  • The registration token expired. For example, Google might decide to refresh registration tokens or the APNS token may have expired for iOS devices.
  • The client app was updated, but the new version is not configured to receive messages.

一般来说,您的代码不应该关心为什么令牌变得无效。您的客户端代码应该通过在应用程序启动时始终报告最新令牌来简单地补偿任何更改,或者使用客户端 API 提供的侦听器生成新令牌。例如,onNewToken will listen to token changes on Android。并且您的服务器代码应删除生成上述错误消息的所有标记。