I need some help with registering an iOS device for multiple templates with Azure Notification Hubs.
Registering for a single template works fine but it seems like when registering for multiple templates from a single device, the second template that is registered for always works fine and the first template that is registered for does not work correctly.
I found something the other day saying that each template had to have a unique PNS Handle but even getting (what I think might be) 2 unique PNS Handles does not seem to work.
Templates #1:
{"aps":{"title":"$(emergencyTitle)","alert":"$(emergencyMessage)","tags":"$(emergencyTags)"}}
Template #2:
{"aps":{"content-available":1,"title":"$(regularTitle)","alert":"$(regularMessage)","inAppMessage":"$(regularMessage)","tags":"$(regularTags)"}}
The code below gets called twice (which I was hoping would get 2 unique PNS Handles). Each time, it saves the deviceToken
in a variable so that I can register the 2 templates with them:
if(UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) {
UIApplication.SharedApplication.RegisterUserNotificationSettings(UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new Foundation.NSSet()));
UIApplication.SharedApplication.RegisterForRemoteNotifications();
} else {
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound);
}
Then the following stripped down code makes the call to the notification hubs to try and register the 2 templates:
Hub = Hub ?? new WindowsAzure.Messaging.SBNotificationHub(Constants.ConnectionString, Constants.NotificationHubPath);
// App.PushNotificationPnsHandles is a Dictionary<string, object> that holds an 'emergency' or 'regular' key and the deviceTokens
// Constants.EmergencyNotificationTemplate and Constants.RegularNotificationTemplate hold the template strings
Hub.UnregisterAllAsync((NSData)App.PushNotificationPnsHandles["emergency"], error => {
Hub.RegisterTemplateAsync((NSData)App.PushNotificationPnsHandles["emergency"], "EmergencyTemplate", Constants.EmergencyNotificationTemplate, System.DateTime.Now.AddDays(90).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US")), new NSSet(), errorCallback => { });
});
Hub.UnregisterAllAsync((NSData)App.PushNotificationPnsHandles["regular"], error => {
Hub.RegisterTemplateAsync((NSData)App.PushNotificationPnsHandles["regular"], "RegularTemplate", Constants.RegularNotificationTemplate, System.DateTime.Now.AddDays(90).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US")), new NSSet(), errorCallback => { });
});
Again, if I make a single call to register for the emergency template everything works great. If I make a single call to register for the regular template everything works great.
If I try to register for the emergency template first and then the regular template, then I send an emergency push notification, a push notification does indeed arrive at the phone but it contains no text in any of the variables... Not sure what I am doing wrong here. Thanks.
Edit: Looking in the Notification Hub debug window in Visual Studio, I can see 2 registrations, each with a different Registration ID but with the same PNS Identifier. If this is the case then I am not sure how to get unique identifiers for each template.