2

we have recently set up GCM for an application for push notifications. The server api is in Node.js so I am using the node module node-gcm for pushing the notifications to gcm server.

We noticed sometimes the packets were not getting delivered to the end user. After doing some search, I tweaked some of the settings which helped a lot to improve the reliability

I changed the older settings to the following new settings:

  • delayWhileIdle flag from true to false,

  • collapseKey to time of day instead of 'demo'

  • timeToLive to 7200 instead of 3

I also read about canonical id's. The google's page "A canonical registration ID is defined to be the ID of the last registration requested by your application. This is the ID that the server should use when sending messages to the device."

I logged the result while sending the message. The canonical id in the result was 0. What does this mean ? Here is the result:

{ 
  multicast_id: 9180653668551804000,
  success: 1,
  failure: 0,
  canonical_ids: 0,
  results: [ { message_id: '0:1415521804106240%0209acc19067cebd' } ] 
}

The post here on stackoverflow suggests to replace the registration id with the canonical id. I am not clear on when to replace and when not to.

In my server's database reg_id is requested when app is installed and stored with the user's record in the database. Also what are these fields like message_id and multicast_id in the result ?

Community
  • 1
  • 1
Mandeep Singh
  • 7,674
  • 19
  • 62
  • 104

1 Answers1

11
  1. The canonical id = 0 means that registration id which your push sever used is OK and not should be replaced by canonical id, i.e. often GCM server will be response canonical_id = 0. If for some reasons your server sends push on not actual registration id GCM server's response will be:

    GCM HTTP status: 200 GCM response body:

    {
        "multicast_id": 7036866281258904189,
        "success": 1,
        "failure": 0,
        "canonical_ids": 1,
        "results": [
            {
                "registration_id": "APA91bH88lV-u5XNdJoF5p0W2d0F_z_7AM6_cjx1e62s83bvDZYcdU_lkmRaFdnkZ5PPUBdYssfpB2QygMW5V0kTqVpV4atCyKpnBEkVnd_YTY0qr4V9oHSyYpv_HIDGNzpfHyGfXz5fWCKnlnACHr37y1zT91JcrHyUMR6DB15WzwjAE1QtloI",
                "message_id": "0:1415529915241995%64ac3713f9fd7ecd"
            }
        ]
    }
    

Now, cannonical_ids = 1 and it means that your server has to replace existing registrtation id on new value which you see in response. This case easy reproduce if user reinstall your client application, but your push server doesn't know about it and GCM server will pass in response new registration id. You can test this situation on my test push server

  1. @mandeep_m91 as to message_id and multicast_id i just suggest you read documentation. In a practise i haven't use this fields yet
sohel khalifa
  • 5,602
  • 3
  • 34
  • 46
Samik
  • 890
  • 1
  • 8
  • 16