gpt4 book ai didi

android - GCM 在 onTokenRefresh() 之后重新订阅主题

转载 作者:行者123 更新时间:2023-11-30 01:42:31 25 4
gpt4 key购买 nike

从Google Developer网站上,我发现GCM Token可能会在一段时间后发生变化:

The Instance ID service initiates callbacks periodically (for example, every 6 months), requesting that your app refreshes its tokens. It may also initiate callbacks when:

There are security issues; for example, SSL or platform issues.

Device information is no longer valid; for example, backup and restore.

The Instance ID service is otherwise affected.

我有一个使用 GCM 主题订阅发送推送通知的 Android 应用程序,在这种情况下,当刷新 token 时,我是否需要再次重新订阅所有主题或 GCM 服务器会自动执行此操作?提前谢谢你。

最佳答案

我已经测试过,当 token 刷新时(您收到一个新 token ),您必须重新注册所有主题。

也结账this SO

示例测试:

  1. 获取 token (“...b43sCSdoEDkU54SIWll3hbDVsd7E1UdwlAvp4LP”)
  2. 注册主题。
  3. 发送主题通知
  4. 有效!
  5. 重启应用几次,仍然会收到主题通知
  6. 强制调用

instanceID.getToken(defaultSenderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);

  1. token 刷新(“...XVT_pZq7fy_vKmskiGpDXMyqdAF6ODl_46JMdi5”)
  2. 发送主题通知。我不明白!

更多详情:

工具 #1使用 this检查谷歌 gcm 数据

  1. 重新安装应用
  2. 获取新 token ("")

工具 #1 的响应

{
"applicationVersion": "39",
"connectDate": "2016-01-12",
"application": "com.esportlivescore.develop.debug",
"authorizedEntity": "11443413691531",
"connectionType": "MOBILE",
"appSigner": ".................",
"platform": "ANDROID"
}
  1. 订阅主题

工具 #1 的响应

{
"applicationVersion": "39",
"connectDate": "2016-01-12",
"application": "com.esportlivescore.develop.debug",
"authorizedEntity": "11443413691531",
"rel": {
"topics": {
"match-28388-start": {
"addDate": "2016-01-13"
}
}
},
"connectionType": "MOBILE",
"appSigner": ".................",
"platform": "ANDROID"
}
  1. 主题消息有效
  2. 请求新 token (刷新)
  3. Google 重新向我发送旧 token :)
  4. 再次……
  5. 现在我没有任何订阅:(

关于android - GCM 在 onTokenRefresh() 之后重新订阅主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34254015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com