0
votes

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

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;

  1. Why am I not registering?
  2. How can I learn why am I not registering?
  3. 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
1
Show the code in the RegisteredForRemoteNotifications method. Do you register with the notification hub there?Gerald Versluis
I have added RegisteredForRemoteNotifications method to the question.aliyasar
Did you use breakpoints to see what the results are? Chances are that the registration with Azure are never made. But nothing is done with the errors so you wouldn't knowGerald Versluis
Yes, I used the breakpoint to see results. IsRegistered always false. I have checked again ConnectionString and NotificationHubName from Azure and same with the fields in my project.aliyasar

1 Answers

0
votes

Solved it by using physical iPhone device.

"The simulator does not do Push Notifications. And to push from a server, you have to have device(s) to push to as well as your app on that device."


"The iPhone Simulator is unable to receive push notifications or successfully register for them."

enter image description here