onTokenRefresh后GCM重新订阅主题() [英] GCM re-subscribe topics after onTokenRefresh()

查看:483
本文介绍了onTokenRefresh后GCM重新订阅主题()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是谷歌开发人员网站,我发现GCM令牌可能一段时间后进行更改:


  

的实例ID服务周期性地发起回调(例如
  每6个月),要求您的应用程序刷新其令牌。它可能
  还发起回调时:


  
  

有安全问题;例如,SSL或平台的问题。


  
  

设备信息不再有效;例如,备份和恢复。


  
  

实例ID服务受到其他影响。


我使用GCM主题订阅发送推送通知的Andr​​oid应用程序,在这种情况下,当令牌已被刷新,我需要再次重新订阅所有主题或GCM服务器会自动做呢?
谢谢你在前进。


解决方案

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

另外结账<一个href=\"http://stackoverflow.com/questions/33739519/clearing-app-data-not-clearing-gcm-token-nor-gcm-subscribing-topics/34786499#34786499\">this SO

样品测试:


  1. 获取令牌(... b43sCSdoEDkU54SIWll3hbDVsd7E1UdwlAvp4LP)

  2. 注册的话题。

  3. 发送通知的主题

  4. 作品!

  5. 重新启动几次的应用,仍然可以得到为主题的通知

  6. 强制呼叫

instanceID.getToken(defaultSenderId,GoogleCloudMessaging.INSTANCE_ID_SCOPE);


  • 令牌刷新(... XVT_pZq7fy_vKmskiGpDXMyqdAF6ODl_46JMdi5)

  • 发送通知的话题。我不明白!

  • 更多细节:

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


    1. 重新安装应用程序

    2. 获取新令牌()

    工具#响应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:

    1. Get token ("...b43sCSdoEDkU54SIWll3hbDVsd7E1UdwlAvp4LP")
    2. Register for topic.
    3. Send notification for topic
    4. Works!
    5. Restart few times app and still get notification for topic
    6. Force call

    instanceID.getToken(defaultSenderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);

    1. Token refreshed ("...XVT_pZq7fy_vKmskiGpDXMyqdAF6ODl_46JMdi5")
    2. Send notification for topic. I don't get it!

    More details:

    Tool #1 Use this to check google gcm data

    1. Reinstall app
    2. 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"
    }
    

    1. 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"
    }
    

    1. Messages for topic are working
    2. Request new token (refresh)
    3. Google resend me old token :)
    4. Again...
    5. Now i don't have any subscriptions :(

    这篇关于onTokenRefresh后GCM重新订阅主题()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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