简体   繁体   中英

How can I send apple push notifications based on userIDs not only on device tokens?

I use push notifications in my iOS application but the problem is - several users with different IDs in the system can use the same device and I want to send push notification only to the user which is logged in, but now notifications arrive to the device even if other user is logged in. I know that APNS identifies pushes only by device tokens...

But is there some way to send push notifications based on user ID or other information not only device token?

You'll have to manage it yourself.

  • Whenever a user logs-in to your app, notify your server (send the user-id to the server).
  • Do the same whenever a user logs-off.
  • In your server, based on the currently logged-in user (you'll have to manage a database that contains for each device token the currently logged-in user), you can decide which push notification to send to the device.

I don't think iOS push notification is right for your problem. here is why

consider you have an app with multiple users using the same device. you have a simple scenario where users can assign tasks to other users and they would like to get notifications when a task has been assigned to them

you do 'user to device token' mapping yourself on the server. consider user A and user B. both registered to receive notifications. so on the server both of them will have an entry in the mapping of what their device tokens are

Now, user B is logged out -- you will update on the server by removing the token for user B? or say use a flag to update the status that he is logged out?

user A now assigns a task to user B. on the server, you can see that user B has no mapping or mapping status is not active?

what happens to the notification?

you will end up queuing a notification for user b until he logs in? and push again? but again how do you know when to push again?

It is better you provide some UX in the app to get the notifications on a tap or periodically poll the server for any notifications

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM