Process duplicate entries in the azure notification hub for the same device

I use the Windows Azure notification hub in my application to provide notifications to the user. Below is the API code that registers devices in the notification center.

var platform = registrationCall["platform"].ToString();
var installationId = registrationCall["instId"].ToString();
var channelUri = registrationCall["channelUri"] != null ?
    registrationCall["channelUri"].ToString() : null;
var deviceToken = registrationCall["deviceToken"] != null ?
    registrationCall["deviceToken"].ToString() : null;
string RegistrationID = registrationCall["RegistrationID"] != null ?
    registrationCall["RegistrationID"].ToString() : null;

var userName = HttpContext.Current.User.Identity.Name;

RegistrationDescription registration = null;
AppleRegistrationDescription iosExistingRegistrationByDeviceToken = null;
string UserID = User.Identity.GetUserId().ToString();

var registrationFromHub = await hubClient.GetRegistrationsByChannelAsync(deviceToken, 100);
if (registrationFromHub.Count() >= 1)
{
    iosExistingRegistrationByDeviceToken =
        registrationFromHub.Where(x => x.RegistrationId == RegistrationID)
                           .SingleOrDefault() as AppleRegistrationDescription;
}

if (iosExistingRegistrationByDeviceToken != null)
{
    iosExistingRegistrationByDeviceToken.Tags = new HashSet<string>() { updated tag list };
    registration =
        await hubClient.UpdateRegistrationAsync(iosExistingRegistrationByDeviceToken);
}
else
{
    registration = await hubClient.CreateAppleNativeRegistrationAsync(deviceToken,tags);
}

My device passes information to this API method. I call this method to create a new registration, as well as to update an existing registration. But it doesn't seem to be working properly.

PNS (Device Token). -, , , . , , - (PNS), .

enter image description here

+5

All Articles