Get GCM canonical registration ID without sending a message

后端 未结 3 542
眼角桃花
眼角桃花 2021-02-06 05:12

I have a problem with an app using GCM, the scenario is this:

  1. the app is installed
  2. the app calls the GCM register method getting the registration id \"RID
3条回答
  •  逝去的感伤
    2021-02-06 05:40

    You can specify "dry_run": true option in /send request.

    I found that devices do not receive any push notifications with "dry_run": true option, while a server get canonical_ids response.

    Here is a sample code in Ruby. You may have to install gcm Gem beforehand.

    $ gem install gcm

    ask_canonical_ids.rb

    require 'gcm'
    require 'json'
    
    API_KEY = "YourApiKey"
    gcm = GCM.new(API_KEY)
    
    registration_ids = [
      'OldRegistrationId',
    ]
    
    option = { data: { 'message' => 'Hello Gcm!' }, dry_run: true }
    response = gcm.send_notification(registration_ids, option)
    
    p response[:canonical_ids]
    

    output of $ ruby ask_canonical_ids.rb (formatted)

    [{
      :old => "OldRegistrationId",
      :new => "NewRegistrationId"
    }]
    

    Again, your device will not receive any push notifications.

提交回复
热议问题