In this article I’ll show you how to fix the “Error updating notification hub” issue when you’re trying to setup your Apple Push Notification Service using the (APNS) settings screen for your Azure Notification Hub using the token-based authentication approach (using the key from a .P8 file).
Setting Up Notifications For Your Xamarin Project
Microsoft has many great resources that help developers to implement the wildest of solutions. And they tend to document them very well.
Once in a while though, you might get stuck even when you’re following their very instructions step-by-step.
Microsoft has very nice documentation on how to set up push notifications using their Azure Notification Hub service:
In this tutorial, you get step-by-step information on how to:
- Set up Push Notification Services and Azure Notification Hubs.
- Create an ASP.NET Core Web API backend application.
- Create a cross-platform Xamarin.Forms application.
- Configure the native Android project for push notifications.
- Configure the native iOS project for push notifications.
- Test the solution.
The tutorial indicates that for Apple, the token-based authentication approach (which is indicated as “OPTION 2” throughout the tutorial) is the most recent and preferred way to setup your ASPN connection. So that’s what I chose to setup.
But as I was following the steps precisely as described, I could not configure the ASPN settings for my notification service.
The error that I kept getting while filling out all the information and after pressing Save, was “Error updating notification hub”:
I tried and tried, checking all the information that was needed and to see if I made an error copy pasting somewhere (like the key from the P8 file that was being used for the “Token” field in the setup screen).
But nothing helped.
What’s Going On?
In order to find out what was going on, I was going to dive into what was causing the error.
Because the message “error updating notification hub” really isn’t telling us much now, is it?
In order to find the reason behind this error, I did the following:
- click on the Notifications icon (the bell) in the top right bar so it shows them most recent notifications
- I clicked the “More events in the activity log” link
The activity log shows the activity that has been going on on your Azure account and in the case of our “error updating notification hub” error, it showed the failed update attempt as well:
The message for the failed update attempt shows what might be wrong:
“On or more of the following properties is incorrect: APNS Token, Key Id or Applciation Id…
The reason for the error
Now we’re getting somewhere.
As I mentioned, I validated the information multiple times and I was sure of the following:
- the APNS token was copied correctly
- I used the right Key Id 💯
- Application Id is the reversed URL name specification, which is shown as the “Bundle Id” on the configuration screen (which I entered correctly for sure)
That only left me thinking that my Team Id might be wrong?
And that was exactly what caused the error in my case:
- In basic Apple account setups, the App Id (ie: com.yourcompany.yourapp) is prefixed by the Team ID
- I entered the App ID prefix ( 2XXXXXX) as the Team Id
The tutorial actually tells you to note this prefix to use it later on:
OPTION 2: Creating a p8 certificate that can be used for token-based authentication
1. Make note of the following details:
– App ID Prefix (Team ID)
– Bundle ID
But when I got to check out my Apple Membership page, It indicated that my Team Id was a different one than the one used as prefix for my App Id.
Why that is the case is probably another post, but i think it’s that way because I’ve teamed up with other parties and re-enabled my account in the past.
The Team ID was NXXXXXX.
As soon as I copy-pasted in that as the Team Id and entered all the other settings conform the tutorial, I was good to go!
To Conclude
In this post, you’ve learned the following things:
- If there’s an error in Azure while configuring something, you can consult the activity log to find out what’s going on
- Team Id’s aren’t necessarily the same as the App Id’s prefix number
- When you can’t save your APNS settings for your Notification Hub, check your Membership page for the Team Id
I hope this saves you some time so you can setup your Notification Hub and get on with implementing awesome solutions.
Code Hard, Ship Harder! 🔥