Take an app which is an e-mail client and gets push notifications when a new e-mail has arrived.
How do these apps make sure that when a push notification has arrived it's for the currently logged-in user?
For example, user logs-in with user1
then logs out and logs in with user2
.
What if a push notification related to a new e-mail for user1
arrives when user2
is logged in?
From the push notification communication mechanism point of view, this is possible. The push notification can be already on the way when user switches logins.
The problem is on iOS when a new push notification has arrived, your code doesn't get called if the app is not in foreground.
This changed a bit with iOS 7 (https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW10) yoru code gets called, but the push notification is still displayed without your code, meaning you can't decide weather to display it or not. This is different than Android where you can always decide.