onTokenRefresh后GCM重新订阅主题() [英] GCM re-subscribe topics after onTokenRefresh()
问题描述
这是谷歌开发人员网站,我发现GCM令牌可能一段时间后进行更改:
的实例ID服务周期性地发起回调(例如
每6个月),要求您的应用程序刷新其令牌。它可能
还发起回调时:
有安全问题;例如,SSL或平台的问题。
设备信息不再有效;例如,备份和恢复。
实例ID服务受到其他影响。
块引用>我使用GCM主题订阅发送推送通知的Android应用程序,在这种情况下,当令牌已被刷新,我需要再次重新订阅所有主题或GCM服务器会自动做呢?
谢谢你在前进。解决方案我已经测试过,当令牌刷新(您收到一个新的令牌),你必须重新注册的所有主题。
另外结账<一个href=\"http://stackoverflow.com/questions/33739519/clearing-app-data-not-clearing-gcm-token-nor-gcm-subscribing-topics/34786499#34786499\">this SO
样品测试:
- 获取令牌(... b43sCSdoEDkU54SIWll3hbDVsd7E1UdwlAvp4LP)
- 注册的话题。
- 发送通知的主题
- 作品!
- 重新启动几次的应用,仍然可以得到为主题的通知
- 强制呼叫
instanceID.getToken(defaultSenderId,GoogleCloudMessaging.INSTANCE_ID_SCOPE)
;
- 令牌刷新(... XVT_pZq7fy_vKmskiGpDXMyqdAF6ODl_46JMdi5)
- 发送通知的话题。我不明白!
更多细节:
工具#1
使用这检查谷歌GCM数据
- 重新安装应用程序
- 获取新令牌()
从工具#响应1
{
applicationVersion:39,
connectDate:2016年1月12日,
应用程序:com.esportlivescore.develop.debug
authorizedEntity:11443413691531,
connectionType:MOBILE,
appSigner:.................
平台:ANDROID
}<醇开始=3>
订阅主题 从工具#响应1
{
applicationVersion:39,
connectDate:2016年1月12日,
应用程序:com.esportlivescore.develop.debug
authorizedEntity:11443413691531,
相对:{
主题: {
MATCH-28388启动:{
ADDDATE:2016年1月13日
}
}
},
connectionType:MOBILE,
appSigner:.................
平台:ANDROID
}<醇开始=4>
为主题的消息正在 申请新的令牌(刷新) 谷歌重新发送我大令牌:) 同样... 现在,我没有任何订阅:( From Google Developer website, I found that GCM Token may be changed after period of time:
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.
I have an android app using GCM Topic subscriptions to send push notification, in this case, when token has been refreshed, do I need to re-subscribe all topics again or GCM server will automatically do it ? Thank you in advance.
解决方案I have tested that when token is refreshed (you receive a new token) you have to register all topics again.
Also checkout this SO
Sample test:
- Get token ("...b43sCSdoEDkU54SIWll3hbDVsd7E1UdwlAvp4LP")
- Register for topic.
- Send notification for topic
- Works!
- Restart few times app and still get notification for topic
- Force call
instanceID.getToken(defaultSenderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE)
;
- Token refreshed ("...XVT_pZq7fy_vKmskiGpDXMyqdAF6ODl_46JMdi5")
- Send notification for topic. I don't get it!
More details:
Tool #1 Use this to check google gcm data
- Reinstall app
- Get new token ("")
Response from tool #1
{ "applicationVersion": "39", "connectDate": "2016-01-12", "application": "com.esportlivescore.develop.debug", "authorizedEntity": "11443413691531", "connectionType": "MOBILE", "appSigner": ".................", "platform": "ANDROID" }
- Subscribe for topic
Response from tool #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" }
- Messages for topic are working
- Request new token (refresh)
- Google resend me old token :)
- Again...
- Now i don't have any subscriptions :(
这篇关于onTokenRefresh后GCM重新订阅主题()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!