$cordovaPush.unregister is not working


#1

When I do

$cordovaPush.unregister().then (response)->
      console.log(response, 'unregistered')

I receive ‘OK’ in response, but i still receive notifications.


#2

Found this:

In particular, you should never unregister your app as a mechanism for logout or for switching between users, for the following reasons:

A registration ID isn’t associated with a particular logged in user. If you unregister and then re-register, GCM may return the same ID or a different ID—there’s no guarantee either way.
Unregistration may take up to 5 minutes to propagate.
After unregistration, re-registration may again take up to 5 minutes to propagate. During this time messages may be rejected due to the state of being unregistered, and after all this, messages may still go to the wrong user.
To make sure that messages go to the intended user:

Your app server can maintain a mapping between the current user and the registration ID.
The app can then check to ensure that messages it receives match the logged in user.

But I still don’t understand how to prevent device receiving notifications if user logs out


#3

I don’t unregister the user. Registering is telling Apple/Google where to send notifications - you only want to forget that when the user actually removes the app from their device or expressly states they don’t want any notifications any more.

If you want to stop the user getting notifications, eg when they log out, call an endpoint on your API (eg GET /logout) when they click the logout button on your app and set the ‘user is logged in’ record in your database to false. When it’s time to send them a notification check the database for the ‘user is logged in’ flag, and just don’t send the notification if they’re not. Whether or not a user gets a notification should be be something you control. You shouldn’t just send them anyway and hope Apple/Google stops them getting to the user’s device.


#4

Thanks that makes sense.