Reputation: 1848
Google Cloud Messaging (GCM) allows the sending of a push notification to multiple devices in a single request. In the event that a user has uninstalled the app I receive a NotRegistered error response. How can I tell which of the multiple devices has had the app removed (and thereby unregister them and not send them any more notifications)?
Should I play safe and simply send one message per device (treating the multiple device-option as an all-user broadcast) or do alternatives exist?
Upvotes: 1
Views: 632
Reputation: 111
If you are sending push notifications to more than one device (registration_ids
) in a single request then your best bet is to use the JSON interface as opposed to the plain-text interface. The JSON interface will respond with an object showing the number of successes and failures along with a list of results
objects for each device you sent a push notification to.
Unfortunately, the example in the documentation here: http://developer.android.com/google/gcm/http.html shows an incorrect format.
Here is an example response:
{
"multicast_id":123456,
"success":1,
"failure":1,
"canonical_ids":0,
"results":[
{"message_id":"0:abcde"},
{"error":"NotRegistered"}
]
}
You can first check the number of failure
s and, if there failures, iterate through the list of results
. The number of elements in results
will be the same as the number of push messages you sent and the order is the same as the registation_ids
specified in the request. You can now find the errors and tally which devices are NotRegistered
or are even an InvalidRegistration
; both meaning that the registation_id is no longer valid and your server should stop sending it push notifications.
Upvotes: 1