4

I understand that the following question is not directly related to code but we really need some input on best practices for push notifications.

We are currently building a chat application that uses push notifications to inform users that a new message is available. Thats nothing new and nothing fancy...we also have the code already in place that allows us to do that:

  • At device start app requests a device tokens
  • Gets device token
  • Registers with push server
  • Done and it works

However my question rather about what to do when the app user context changes. For example:

  1. User A logs into app, receives device token, registers device
  2. User A logs out
  3. User B logs into app on the same device, gets same device token, registers device again but device is already known.

At this point we currently have the issue that app still receives push notifications from user A because the push server thinks that this devices is still under user context A.

Of course we could implement a de-register function that removes the device at logout but what happens if the app gets deleted and re-added. For example:

  1. User A logs and receives push notifications
  2. User B deletes app on the same devices
  3. User B downloads the app again and gets the device token

At this point again the device receives push notifications from user A even though no user is even logged in.

It seems to me that we are missing a crucial step in our thinking but we don't what that is...we cannot request a new device token afaik.

Thanks in advance

user3757285
  • 117
  • 1
  • 1
  • 8
  • you should not use a device token to identify a user. in your case, your server should store user-unique information, like email, with a token. then deliver a notification, only when it's recipient matches the user. – bluedome Dec 18 '14 at 05:47
  • Thanks @bluedome but we kind of already do that. The question now would be how to determine if a device expired? Lets say I store a unique identifier on the server and the server determines what device to push to it can still occur that two users were registered with the same device. So I must find a way to invalidate the device for the previous user – user3757285 Dec 18 '14 at 18:47

0 Answers0