Not Receiving Notifications on iOS devices from Azure Notification Hub using a Custom Template
I have two registered both Android and iOS devices on my Notification Hub with custom template registrations.
When I send a notification using a custom template "newJobRequestTemplate", Android receives it and displays it, but iOS does not.
Sending a notification using the custom template "textMessageTemplate" works fine on both devices.
My iOS device installation (registration) looks like this:
{
"installationId": "ab1ad748**********************",
"userId": "1f429963",
"pushChannel": "6EB8E**************************",
"pushChannelExpired": false,
"platform": 2,
"expirationTime": "9999-12-31T23:59:59.9999999Z",
"tags": [
"userId:1f429963"
],
"pushVariables": null,
"templates": {
"newJobRequestTemplate": {
"body": "{\"aps\":{\"template\":\"newJobRequestTemplate\",\"title\":\"$(title)\",\"date\":\"$(date)\",\"address\":\"$(address)\"}}",
"headers": null,
"expiry": null,
"tags": [
"newJobRequestTemplate"
]
},
"textMessageTemplate": {
"body": "{\"aps\":{\"template\":\"textMessageTemplate\",\"alert\":\"$(message)\",\"title\":\"$(title)\"}}",
"headers": null,
"expiry": null,
"tags": [
"textMessageTemplate"
]
}
},
"secondaryTiles": null
}
When I do a Test Send from Azure Portal to the Tag expression: newJobRequestTemplate with the payload below, only Android receives it, iOS doesn't
{
"title":"New job available",
"date":"July 16",
"address":"New York"
}
But when I do a Test Send from Azure Portal to the Tag expression: textMessageTemplate with the payload below, both Android and iOS receive it no problems.
{
"title":"Test title",
"message":"Test message"
}
Here's the code I have in my iOS project
AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Xamarin.FormsMaps.Init();
UNUserNotificationCenter.Current.Delegate = new iOSNotificationReceiver();
if(UIDevice.CurrentDevice.CheckSystemVersion(8,0))
{
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
UIRemoteNotificationType notificationType = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationType);
}
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
And iOSNotificationReceiver.cs
public class iOSNotificationReceiver : UNUserNotificationCenterDelegate
{
// Called if app is in the foreground.
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action