ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 206 forks source link

does it possible to receive invalid token like apple feedback? #221

Closed breaklee closed 8 years ago

breaklee commented 8 years ago

i want to delete tokens already deleted in mobile apps. how do i know this situation?

hypesystem commented 8 years ago

If you try to send a notification to a device and get an error "NotRegistered" it means that it has been deleted.

It is your own responsibility to make sure that your app informs your server that a registration id has been removed.

sunojvijayan commented 8 years ago

That is nice but when you are sending 1000s at a time is there a way to know which one is not registered. Thanks

eladnava commented 8 years ago

@sunojvijayan Yes, you can match the returned result to a specific registration ID via its index in the array.

For example, if you send a push to 5 registration IDs, the results array will be populated with indexes 0 to 4 each relating to the registration IDs you provided, in the same order you sent them.

hypesystem commented 8 years ago

A more concrete example of what @eladnava describes:

If you registration ids are [ "A", "B", "C", "D", "E" ] and "C" is no longer registered, the response will look something like this:

{
  "multicast_id": "something",
  "success": 4,
  "failure": 1,
  "results": [
    { "message_id": "something" },
    { "message_id": "something" },
    { "error": "NotRegistered" },
    { "message_id": "something" },
    { "message_id": "something" }
  ]
}

Notice that the response with error has index 2 --- this maps to the index 2 of your registration IDs, ie. "C".

The spec can be found here: https://developers.google.com/cloud-messaging/http-server-ref#table5

sunojvijayan commented 8 years ago

Thank you guys. Great work.