2

We have a really weird problem with the remote notifications on iPhone. Device just doesn't receive remote notifications however registration works fine. We checked all certificates and also provisioning profile, also tried to send test notification directly from Azure, the same result as we send with our api. When app is installed from HockeyApp notifications works fine. In debug DidReceiveRemoteNotification method is just not called.

public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
     // Opened by push notification.
     if (application.ApplicationState == UIApplicationState.Background || application.ApplicationState == UIApplicationState.Inactive)
     {
          // Make userInfo readable.
          PushNotification notification = CrossDevice.Current.ConvertToNotification(userInfo);
     }

      // Process notification so we can attach to it's received event.                               
      CrossAzurePushNotifications.Platform.ProcessNotification(userInfo);

     // No data is altered.                                
     completionHandler(UIBackgroundFetchResult.NoData);
}

Note: we are using AzurePushNotifications plugin

xamarin forum question

Mony
  • 93
  • 1
  • 11
  • Are you using an iPhone device for testing notifications or the iOS simulator? – ganchito55 Jun 29 '17 at 10:18
  • 1
    Notifications don't come through on a simulator, so you must be using an actual apple device, secondly your notification hub must be set up in 'sandbox' mode (ideally, although production does sort of support both dev and release). – JoeTomks Jun 29 '17 at 10:24
  • We use physical device, notification hub is set to production with corresponding certificate. It was configured like this from beginning. The problem is that notifications have worked few weeks ago with same settings of hub while debbuging. I'm sure that this is not because of code changes in app as I checked also older versions with the same result. – Mony Jul 03 '17 at 08:58

2 Answers2

2

You should use the 'sandbox' for testing with the debugger attached. See this link or this link for more information about sandbox vs production.

Please also note that switching from production to sandbox in Azure NotificationHub does not always work. Best solution is to create a separate notification hub for test and production.

Tom
  • 874
  • 7
  • 13
  • Both you and @Ivan are right. After creating new hub for production and made sure that first one is set to sandbox notifications work also in debug mode. However it is still not clear to me why it worked before. I'm sure we used only one hub and only one certificate and ad-hoc provisioning profile. – Mony Aug 29 '17 at 08:27
  • I am glad your issue is solved. I do not know why it worked before. Maybe Apple updated their servers or something like that. However, this is how it should be. – Tom Aug 29 '17 at 11:49
2

You need two Notifications Hub: one for testing and one for production.

If you are developing and running the App from Xcode, you have to use the testing Hub with a testing certificate and when you want to upload it to the Apple Store o TestFlight, you have to change the URL and use the Production Hub. If not, there is not woing to work.

You need different certificates, you can check the process here: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-ios-apple-push-notification-apns-get-started

Here is when you decide what kind of certificate you have to choose: https://learn.microsoft.com/en-us/azure/includes/media/notification-hubs-enable-apple-push-notifications/notification-hubs-appid-create-cert.png

Ivan
  • 73
  • 10