Deal with duplicate entries in azure notification hub for the same device

喜夏-厌秋 提交于 2019-12-07 04:11:31

问题


I am using windows azure notification hub in my application to provide notifications to the user. Below is the code of the API that registers the devices on notification hub.

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 the information to this api method. I am calling this method to create new registration as well to update the existing registration. But it doesn't seem to be working properly.

The screen shot below shows the duplicate entries with the same PNS ( Device Token ). CAn anyone please help me how to avoid this duplicate entries. What i want is if the notification hub already contains the Device Token ( PNS ) then it should simply upodate the tags instead of creating new registration.

来源:https://stackoverflow.com/questions/25052010/deal-with-duplicate-entries-in-azure-notification-hub-for-the-same-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!