I have tried Android and Windows push notifications and all works fine. However, on the iOS side, something wrong.
I am trying to add push notifications to my Xamarin.iOS app using these tutorials
- https://docs.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started
- https://blog.xamarin.com/push-notifications-ios-azure-notification-hubs/
From Azure Test Send I got "Message was successfully sent, but there were no matching targets."
I have followed all the steps as it is but when I put a breakpoint, I always get "IsRegistered =false":
AppDelegate.cs
private SBNotificationHub Hub { get; set; }
public const string ConnectionString = "Endpoint=sb://...";
public const string NotificationHubPath = "NotificationHubName...";
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// Set our preferred notification settings for the app
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet());
// Register for notifications
UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
bool IsRegistered = UIApplication.SharedApplication.IsRegisteredForRemoteNotifications;
return true;
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
Hub = new SBNotificationHub(ConnectionString, NotificationHubPath);
Hub.UnregisterAllAsync(deviceToken, (error) =>
{
if (error != null)
{
// Error unregistering
return;
}
// Register this device with the notification hub
Hub.RegisterNativeAsync(deviceToken, null, (registerError) =>
{
if (registerError != null)
{
// Error registering
}
});
});
}
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
{
// Get the aps dictionary from the alert payload
NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
}
}
My questions are;
- Why am I not registering?
- How can I learn why am I not registering?
- Is Xamarin support iOS 11.0 push notification from Azure Notification Hub?
Note: I am using
- Visual Studio 2017 (Version 15.4.0) on Windows 10
- Mac OS High Siera Version 10.13
- Xcode Version 9.0.1
- VS for Mac Community Version 7.2 (build 636)
- Testing on iPhone 5S, iPhone 6, iPhone 6S, iPhone 7, iPhone 8 - iOS11.0
RegisteredForRemoteNotifications
method. Do you register with the notification hub there? – Gerald Versluis