Azure Hub Notifications aren't received on iPhones - Sandbox

PrasanthV 1 Reputation point
2020-10-07T14:30:10.057+00:00

We had followed the below documentation to integrate Azure Notification Hub with Xamarin Forms app.
The notifications are received on Android, but the same notifications aren't received on iPhones (OS : 12+, 13.6, 13.7, 14+)

The notifications are received on iPhones when debugging in Debug mode, when the packages are created in Release mode, we see the notifications aren't received on iPhones.

We are seeing this behavior only today only. Till yesterday, we used to get the notifications on both Debug & Release modes.

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
241 questions
{count} votes

2 answers

Sort by: Most helpful
  1. PrasanthV 1 Reputation point
    2020-10-09T04:21:26.467+00:00

    Hi,

    I had followed the below article, however, few observations:

    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/azure-services/azure-notification-hub#configure-ios-for-notifications

    We are using NotificationHubClient.SendTemplateNotification, which accepts a dictionary<string,string>. Using this, the Android phones are receiving the notifications, but not the iPhones. When investigated, the APNS is expecting to have "aps" JSON element with "title" & "body" in it.
    As the SendTemplateNotification is expecting Dictionary<string,string> the JSON string value is not being accepted in the appropriate format.

    So we end up in using native Notification methods, from NotificationHubClient.

    Now, if you have any working sample, where we can use SendTemplateNotification, please do let us know, which should work for both Android & iPhones.

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.notificationhubs.notificationhubclient.sendtemplatenotificationasync?view=azure-dotnet

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.notificationhubs.notificationhubclient.sendfcmnativenotificationasync?view=azure-dotnet

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.notificationhubs.notificationhubclient.sendapplenativenotificationasync?view=azure-dotnet


  2. Grmacjon-MSFT 13,961 Reputation points
    2020-10-14T00:30:33.753+00:00

    Hello @PrasanthV

    Thanks for your patience. it matters how you registered the device, with the sandbox or production environment, as the APNS tokens will be different for each, and thus rejected if they differ. If you're building in Release mode, then the app is most likely configured for the "Production" APNS endpoint (versus Sandbox). You will need to configure your Notification Hub accordingly. We can confirm if you have the wrong configuration if you have a Notification ID (or Tracking ID) returned by the "send" API for the notification that failed.

    Note: do not switch your Hub back and forth between Production/Sandbox. you should create a Hub for each. You can configure the same credentials on each Hub, but when building your app, you should configure the proper Hub for the build configuration.

    We support sending APNS notifications using templates, but you are is responsible for defining the template in a way that is compatible with APNS. An example template might look like the following:

    {  
      "aps": {  
        "alert": {  
          "title": "$(title)",  
          "body": "$(body)"  
        }  
      }  
    }  
    

    you would need to supply values for the "title" and "body" parameters when you send the notification. The payload at send time would look like:

    {  
      "title": "The title",  
      "body": "The body"  
    }  
    

    Another thing to note is there is no "aps" when specifying the parameter values. It's just a simple dictionary of name/value pairs.

    hope that helps.

    Best,
    Grace

    0 comments No comments