简体   繁体   English

多个用户使用同一设备时处理Apple推送通知的最佳做法

[英]Best practice to handle apple push notification when multiple users uses the same device

My app is user specific. 我的应用是用户特定的。 multiple users can uses the same device.My application has offline logout functionality. 多个用户可以使用同一个设备。我的应用程序具有脱机注销功能。 consider that one of my user (say user 1)logout offline.during that time my server send notification to the APNS for user1. 考虑我的一个用户(比如用户1)注销offline.during那时我的服务器向APNS发送user1的通知。 after some time my device become online. 一段时间后我的设备上线了。 during that time i am not logged in to the app. 在那段时间我没有登录到应用程序。 my question is that while my device is online(when network connection is available)and user1 is logged out will my app receive the push notification from APNS server(those sent for logged out user) 我的问题是,当我的设备在线时(当网络连接可用时)并且user1被注销,我的应用程序将收到来自APNS服务器的推送通知(那些为已注销用户发送的通知)

On logout: [[UIApplication sharedApplication] unregisterForRemoteNotifications]; 注销时: [[UIApplication sharedApplication] unregisterForRemoteNotifications];

On login: 登录时:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

This will help you for sure : 这将有助于您确定:

First you have to request a web service when user logout. 首先,您必须在用户注销时请求Web服务。 This web service remove the token of device for the user who is going to logout from server database. 此Web服务为将要从服务器数据库注销的用户删除设备令牌。

Now you have to add a check (in push notification method at web end which your back end developer is using to send request for push to APNS ) that only push will be send for user who have device token. 现在,您必须添加一个检查(在Web端使用推送通知方法,您的后端开发人员正在使用该方法将请求推送到APNS),只有具有设备令牌的用户才会发送推送。 That's it. 而已。

当用户退出您的应用程序时,您可以以编程方式关闭接收推送通知。如果您没有以编程方式关闭推送通知,它将收到通知,因为您的设备令牌已在服务器上注册(如果您已连接到互联网)

On logged out you should make one service call that simply wipe out token of this user from webserver. 注销后,您应该拨打一个服务电话,只是从网络服务器中清除此用户的令牌。

On successful login of user you should register your device for push notification normally like we are doing. 成功登录用户后,您应该像我们一样注册您的设备以进行推送通知。 So, again your device token will be registered with server for particular logged in User. 因此,您的设备令牌将再次注册到服务器以用于特定登录的用户。

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

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