问题
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