Reputation: 4106
Due to a bug on our system, we mistakenly stored multiple registration ids per device per user by appending to their profile, rather than replacing after an upgrade and the like.
We can obviously now correct that by handling the canonical ids from the response we get, but for some users (like myself, for instance...) they would get multiple notifications, instead of just one per device.
I've read what can be sent via,
http://developer.android.com/google/gcm/http.html
and
http://developer.android.com/google/gcm/server.html#params
But there doesn't seem to be a perfect solution. I've just checked there, and I could send a 'dry_run' request first, handle the multiple registration ids, replace what needs replacing, remove what needs removing, then send the second (pruned) request.
This certainly could be a solution, but I can't imagine it'd be friendly to our api quotas (though I don't really know). Is there no other property that can be set on the HTTP equest so as to only send to an individual device?
Upvotes: 2
Views: 1431
Reputation: 394156
GCM is completely free no matter how big your messaging needs are, and there are no quotas.
(quote from here).
There are no quotas to GCM, so you can try your dry_run approach without fear. The only question is whether dry_run mode actually returns Canonical Registration ID, or simply returns immediately with just some fake message ID.
Using the Canonical Registration ID response is the only way you can use to clean your DB (other than deleting your DB and re-building it from scratch).
There is a small optimization you can make in your cleanup process. If you can fetch the registration IDs from your DB in the order they were inserted (from the oldest to the latest), you will likely get Canonical Registration ID responses for the first registration IDs you try. For each of them you'll know what the current (canonical) registration ID is, and you'll mark it, so you don't send to it during your cleanup process. This will prevent sending duplicate messages for all devices that have up to 2 registration IDs in your DB (and will reduce by one the number of duplicate messages for the other devices).
Upvotes: 2