Forum Xamarin.Forms

Best practice for handling push notifications on a single device with potentially multiple logins

MountainDewMountainDew Member ✭✭
edited January 25 in Xamarin.Forms

I've been reading on how to properly implement push notifications into an app I'm developing and I pretty much have it working successfully. The code registers the device with azure notification hub and successfully sends a notification based on the specified tag that I provide.

My question is what is the best approach for handling the device registration with potentially multiple users that would in turn mean multiple tags? I read that you shouldn't de-register the device once it's registered so that's where I kind of got lost.

I probably don't have the complete understanding of the device registration / assigning a tag either. My understanding is that you register said device with a token that looks to be randomly generated and then you associate a tag with that token (i.e. the device). Should you just add multiple tags (users) to the same token and then just pass the tag around the code so the notification gets sent to the correct tag? Can you just randomly add another tag to an already registered device to handle another person logging in and using the app?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    We could add several tags to a single device. The device token is generated from the client and we could choose to bind the tag to this ID so that it could be a user id. The backend side could send notifications to specific devices through this kind of user id tag.
    However, we sometimes need to group some users based on the same interest or company. When the backend side wants to send the notifications to a group of users, these tags are being used.

  • MountainDewMountainDew Member ✭✭

    Thanks LandLu.

    So do I understand this correctly in that when the device is first registered a token is generated and this is the token that gets followed around for the life of that device or until it is de-registered. When I go to add another tag to the device token (say another user is logging into that app) do I need to specify that I'm adding this tag to this specific token or does the code behind (sorry...I'm still a little rusty on what the registering code does) already know that this specific device is tied to this specific token and it just adds the tag to it automatically.

  • LandLuLandLu Member, Xamarin Team Xamurai

    So do I understand this correctly in that when the device is first registered a token is generated and this is the token that gets followed around for the life of that device or until it is de-registered.

    Yes. But if the user uninstalled the application and installed it again this token will be refreshed.
    If this application hasn't been installed while the user changes I think we should resign the previous user first before registering a new user. I mean we need to remove the former tag as it has no meaning. Or if we tried to get in contact with the previous tag from backend the device will also receive the notification.
    This is not what we want.

Sign In or Register to comment.