Reputation: 3688
i have an cordova App , when user login new "app registrationId" is sent to server and is saved in database for further use (when app user receive a message from someone else ) , however when user logout i want to clear all pending message in gcm , so that if another user login he doesn't receive Previous user notifications.
is there any way to do this in GCM ? or my scenario is totally wrong !?
thanks.
Upvotes: 0
Views: 363
Reputation: 37778
A registration token corresponds to a single app instance (tied to the device) and not to a single user specifically.
I've also searched around about this topic before and the usual solution is for you to have a user identifier included in your payload, let's say a userid
. Then in your client app, you must check if the userid
matches the one who is currently logged-in. If true, show the notification, else, disregard the message.
With this, if a different user is logged-in and a push was sent to that specific registration token, your app will handle it and will not show any details not for the corresponding user.
However, this means that only if the original user is logged-in will your app be showing a notification.
Anyways, it's still a valid workaround for the behavior you're aiming for. Hope that makes sense. Cheers!
Upvotes: 1