Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I handle a multiple accounts app with APNS?

I am currently investigating in an online-offline-supported application and figuring out the usage of APNS, and it is quite easy to understand when my application only deals with single user.(just like SMS)

My understanding is, each application installed to the specific device will have its own device token (and which won't be changed even after unregistration to APNS and re-register again). So, when a user login from different devices, APNS and in turn the server can identify.

However, when I tried to implement a multiple account apps ( just like Facebook, that different people can login using same phone), some questions arose.

When user A logged in and when the app is in background state, yea it did receive the notification.

But when user A logged out (when the phone has no internet connection, which means can't update the server at once for deletion of account), and then user B logged in, meanwhile the server tried to push notification to the phone for user A, the notification has already received by the phone (but that's notification for user A) and user B would receive that (which should never happen in real scenario).

It seems that APNS cannot check in-application account authentication.

So, my questions are,

  1. Is there any way to check and remove the notification on the phone (I've read the Apple Doc. and notice that there is a QoS storing the last notification)?

  2. what is a good practice to handle such kind of authentication problems upon using APNS?

Please, if any, correct me if I do have any conceptual misunderstanding. And hope that my questions don't sound stupid and clumsy and there's not any question duplication ...

like image 649
user1516507 Avatar asked Aug 02 '12 09:08

user1516507


People also ask

Do APNs sandbox?

Apple provides a sandbox endpoint that can be used for testing push notifications. The sandbox ensures that device IDs in that environment will not work in production and are thus safe for testing purposes.

How does APN push notification work?

APNS is a cloud-based service that enables apps to send push notifications from a remote server to iOS users through a secure connection. Before iOS users receive your messages, you'll need a p. 12 certificate from Apple, which authorizes push sending through APNS.

What is APNs priority?

apns-priority. The priority of the notification. If you omit this header, APNs sets the notification priority to 10 . Specify 10 to send the notification immediately. Specify 5 to send the notification based on power considerations on the user's device.


2 Answers

If you have a feature to 'log out' from your app (without logging in a new user), I can't find any way to stop push notifications being sent except by letting the server know that the user has logged out.

If there is no internet connection, no proper logout can be made. If you need to have this feature, you should verify the logout with the server. The user could be informed that the logout failed since the server could not be reached.

Here is an example:

  • User A logs in on device X that has device token TX.

    -> Server associates token TX to belong to user A.

  • User A logs in on device Y that has device token TY.

    -> Server associates tokens TX and TY to belong to user A.

  • Push message sent to user A

    -> Server sends push message to TX and TY.

  • User A logs out from device X and user B logs in on device X.

    -> Server removes association of token TX to user A

    -> Server associates token TX to user B.

  • Push message sent to user A

    -> Server sends push message to TY.

  • Push message sent to user B

    -> Server sends push message to TX.

  • User B logs out, but has no internet connection

    -> Login failed, user B still logged in, receives dialog "Could not log out"

like image 92
jake_hetfield Avatar answered Oct 12 '22 08:10

jake_hetfield


So, at first:

How user A can logout and login in Facebook without internet?

When user B is login, therefore internet is connected, then you can send to your server: now userB at this device token.

And for case: user B logged in, meanwhile the server tried to push notification to the phone for user A

If app is runned, then APNS notification you will get at

application: (UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken: (NSData*)deviceToken

not in device notificaion center message window.

And you can to do this:

1) If userA already in log, then send Local Notification for show a notification

2) If a other user in log OR users is logouted, then to do nothing

Hope it's helped. Maybe i am wrong, if you mean a other.

like image 22
CReaTuS Avatar answered Oct 12 '22 07:10

CReaTuS