Reputation: 45
I am implementing the GCM service on my app, but I have some doubts. When a user installs and opens my app for the first time, it gives him a token to receive notifications, this is saved in the database of my site. When the user decides to uninstall my app, I think the token is not useful anymore, so I was wondering if is possible to know the expired token and delete it from my database.
Upvotes: 3
Views: 221
Reputation: 17429
When your App Server sends a message to GCM Server, trying to reach a client on which your app has been unistalled, it (the GCM Server) should return a NotRegistered Error
. So the app Server should remove the token from the database.
Usually (it actually depends on the client platform) when the app is unistalled, what happens 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.
This means that if noone tries to send message to your client (the one who unistalled the app) you should never be able to understand if a token is still used.
If for you is important to remove all unused tokens, IMHO you can overcome this problem creating a test message that is triggered (for example once a month) from you App Server: this should conduct you to the point 2.
Upvotes: 1