Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for push notifications in multi user applications?

I'm working on a push architecture that needs to support applications which allow for multiple users. This means more than one user can log into the application with their credentials. The problem I'm running into is what if user A allows push notifications, then logs out, then user B logs in and starts getting user A's push notifications?

What are some best practices for handling this type of thing? One thought I had was you could remember the last user who logged in and only display push notifications to the "logged in" user. You would have to send some sort of user context in the message payload so it could be checked against the logged in user. However this feels a little funky.

Anyone else ran into this? It's seems like a really relevant problem, especially for tablets where families tend to share the device.

like image 907
Paul Fryer Avatar asked Sep 18 '12 23:09

Paul Fryer


1 Answers

We're implementing this by Registering the device with APSN, getting the device token and sending this to our server through a ws.

On the server side the device token is only associated with the last logged in user.

New app
User A (first ever user) uses IPAD A
Register with APSN, get token
Send token to our servers through ws
Search for token in db, token is new, store it
assign token to USER A

Next user logs into app
Register with APSN, get token
Send token to our servers through ws
Search for token in db, token exists already
Remove connection to USER A
assign token to USER B

SEND Notification to device WITH USERNAME
if username is logged in show it - else dont

Still not perfect as its sent to home screen first so to ALL users

like image 57
brian.clear Avatar answered Oct 23 '22 09:10

brian.clear