I came to know that GCM marks registration id for deletion when it is unable to send the next push notification.
But in my case following situation happened to my user.
Scenario :
1)My user installed the app and his device is registered with GCM.
2)Same user uninstalled and installed the app again immediately. Second time a new registration id is generated.
3)These two registration ids are stored in my database.
4)Now this particular user is getting two push notifications.
Now I have the following questions :
Questions :
From the official documentation:
How uninstalled client app unregistration works
A client app can be automatically unregistered after it is uninstalled. However, this process does not happen immediately. What happens in this scenario is:
- The end user uninstalls the client app.
- The app server sends a message to GCM connection server.
- The GCM connection server sends the message to the GCM client on the device.
- The GCM client on the device receives the message and detects that the client app has been uninstalled; the detection details depend on the platform on which the client app is running.
- The GCM client on the device informs the GCM connection server that the client app was uninstalled.
- The GCM connection server marks the registration token for deletion.
- The app server sends a message to GCM.
- The GCM returns a NotRegistered error message to the app server.
- The app server should delete the registration token.
Note that it might take a while for the registration token to be completely removed from GCM. Thus it is possible that messages sent during step 7 above get a valid message ID as a response, even though the message will not be delivered to the client app. Eventually, the registration token will be removed and the server will get a NotRegistered error, without any further action being required from the app server.
However, it can apparently happen that you still get the notification for the old registration ID, as users state in other questions:
For this problem, there is a functionality called "canonical IDs":
Canonical IDs
If a bug in the client app triggers multiple registrations for the same device, it can be hard to reconcile state and the client app might end up with duplicate messages.
Implementing canonical IDs can help you more easily recover from these situations. A canonical registration ID is the registration token of the last registration requested by the client app. This is the ID that the server should use when sending messages to the device.
If you try to send a message using an old registration token, GCM will process the request as usual, but it will include the canonical ID in the registration_id field of the response. Make sure to replace the registration token stored in your server with this canonical ID, as eventually the old registration token will stop working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With