简体   繁体   English

如何基于用户ID不仅在设备令牌上发送苹果推送通知?

[英]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... 我在我的iOS应用程序中使用推送通知,但问题是 - 系统中具有不同ID的几个用户可以使用相同的设备,我只想向已登录的用户发送推送通知,但现在通知甚至到达设备如果其他用户登录。我知道APNS识别仅按设备令牌推送...

But is there some way to send push notifications based on user ID or other information not only device token? 但有没有办法根据用户ID或其他信息发送推送通知,而不仅仅是设备令牌?

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). 每当用户登录到您的应用程序时,请通知您的服务器(将用户ID发送到服务器)。
  • 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. 我不认为iOS推送通知适合您的问题。 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. 考虑用户A和用户B.两者都注册接收通知。 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? 现在,用户B已注销 - 您将通过删除用户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? 用户A现在在服务器上为用户B分配任务,您可以看到用户B没有映射或映射状态不活动?

what happens to the notification? 通知怎么了?

you will end up queuing a notification for user b until he logs in? 你最终会为用户b排队通知,直到他登录为止? 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 最好在应用程序中提供一些用户界面以通过点击获取通知或定期轮询服务器以获取任何通知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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