简体   繁体   中英

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. 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)

On logout: [[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. This web service remove the token of device for the user who is going to logout from server database.

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. 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.

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