Azure Notification Hub Application mode using production fails

marc 101 Reputation points
2020-06-01T06:17:44.603+00:00

I followed this tutorial and got the notification hub working for my app in sandbox mode and "Token" is used as authentication method.
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-ios-push-notifications-swift-apps-get-started

I am not sure what the difference is between production and sandbox mode but i guess when I push the app to appstore then the production mode is supposed to be used. After swiching from "sandbox" to "production", the test send generates following outcome "the push notifiication system handler for the registration is invalid".
I mean it is working under "sandbox" mode, which means the devices are using the correct "listen" connectionstring.

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.
325 questions
0 comments No comments
{count} votes

Accepted answer
  1. ajkuma 26,626 Reputation points Microsoft Employee
    2020-06-11T20:07:10.093+00:00

    [Adding the offline discussion with @marc here, to benefit the community]

    The documentation calls out when you’re creating your app, to create certificates for both production and development, which are used for push notifications.
    This has to do with the production or development case doc: or you can use the token based authentication as discussed in option 2.

    Once those certs or tokens have been created, then you need to create a provisioning profile, either production or development mode so that you can deploy the app. Once the device has been registered for development by the app, it is good only for development, not production. Then the development credentials should be set on the Notification Hub, depending on the method chosen either the p12 or p8 file.

    In other words as noted here, when you build your app using a development cert, the app will generate a unique device token. This device token will not work on the production push network. When you then build your app with a distribution provisioning profile (App Store or Ad-Hoc) your device will generate a different device token for push notifications. If you try to send the development generated token to the production push SSL network, Apple's servers will reject your token.

    Update from @marc - " I did get the problem solved after only using the production hub + app downloaded from testflight using appstore provision profile. And everytime i do local development then I just use the local development hub connectionstring, else cant get it work locally with my dev provision profile."

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. ajkuma 26,626 Reputation points Microsoft Employee
    2020-06-03T04:48:18.19+00:00

    Welcome to Microsoft Q&A! Thanks for posting this question.

    Apologies for the delay and any inconvenience with this issue.

    Just to confirm, are you using the same hub or two different hubs with sandbox and production certificates?
    You must maintain two different hubs: one for production and another for testing. You must upload the certificate you use in a sandbox environment to a separate hub than the certificate/hub you'll use in production. Don't try to upload different types of certificates to the same hub. It will cause notification failures. If you inadvertently upload different types of certificates to the same hub, you should delete the hub and start fresh with a new hub. If for some reason you can't delete the hub, you must at least delete all the existing registrations from the hub.

    You may check the steps outlined in the document – ‘Diagnose dropped notifications in Azure Notification Hubs’ to narrow down the issue further.

    As mentioned, the tutorial you are referring for configuring deployment certificate, the same process is used when registering a production certificate. Just make sure that you use the same certificate type when sending notifications.
    Also, just highlighting the points from the same document :

    • The notification hub will be configured to use the Sandbox authentication mode only. You should not use this authentication mode for production workloads.
    • This tutorial uses a development certificate. The same process is used when registering a production certificate. Just make sure that you use the same certificate type when sending notifications.
    • Use the Production for Application Mode only if you want to send push notifications to users who purchased your app from the store.

    Kindly let us know if this helps or you need further assistance we would be more than happy to assist you.

    0 comments No comments

  2. marc 101 Reputation points
    2020-06-03T20:33:02.303+00:00

    Hi, my setup is using two hubs, one for local development testing and one for production. And i am not using certificate, but the token key. The key itself is general purpose and can be used by both testing and production.

    Use the Production for Application Mode only if you want to send push notifications to users who purchased your app from the store.

    this is actually the part that I did not manage to understand earlier until now. When the production mode is used, the notification is routed to the production server from apple. When I am debugging locally, i am using a development provision profile, and I never managed to receive any notification. As for today, I push the app to testflight, then install it from there, so the app is using the appstore provision profile. It seems app is only able to receive production notification when production provision profile is used. I think without this explanation, we as developer will have a hard time to understand what is going on by reading the returned "outcome" object.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.