skip to Main Content

How to find out which device is registered for which user for sending apple native notification?

I am getting all the devices registered in my notification hub with:
var allRegistrations = await _hubClient.GetAllRegistrationsAsync(0);
but this has no information about the users.

2

Answers


  1. Chosen as BEST ANSWER

    You can make use of tags for that. Get the devicetag in app.component.ts

    const deviceTag = await Device.getId() ;
    

    and store it in the database along with the user information. That way, if you want to send notifications to particular user, you can get the device tag from the database of that user and send notification to that particular user.

     await _notificationService.SendNotificationAsync(deviceTags, notification);
    

  2. To establish which user is linked with a certain registration, utilize the UserInformation attribute of each NotificationHubRegistration object.

    var allRegistrations = await hubClient.GetAllRegistrationsAsync();
    foreach (var registration in allRegistrations)
    {
    if (registration.UserInformation != null)
    {
    // User is registered with this registration
    }
    }
    

    If you need to identify the device linked with each user, you may record the registration ID and device ID for each user in a dictionary or other data structure. The registration ID may then be compared to the list of devices registered to the notification hub to locate the appropriate device.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search