.NET MAUI Push Notifications using Azure Notification Hub. Part 1. Setup Azure Notification Hub

.NET MAUI Push Notifications using Azure Notification Hub. Part 1. Setup Azure Notification Hub

14 August 2023

Azure

Buy Me A Coffee

Hello!

Do you recall the last alert you got on your mobile device while using your favorite apps? Yes, those little messages that pop-up on the screen are known as push notifications. Just like you, millions of users globally receive push notifications every day.

Push notifications are an essential tool for modern applications to engage and retain users. They enable immediate communication with the user, provide them with timely updates, nudge their interaction, and considerably elevate the responsiveness of an application, enriching the user experience and generating enhanced business value.

Azure Notification Hubs provide a highly scalable, cross-platform push notification infrastructure that enables you to either broadcast push notifications to millions of users at once or tailor notifications to individual users.

You can use Azure Notification Hubs to push notifications to mobile devices as well as to desktops. This is the first part of the article series on how to set up push notifications in .NET MAUI using Azure Notification Hubs. In this part, you will learn how to set up Azure Notification Hubs along with Windows Notification Service (WNS) and Firebase Cloud Messaging (FCM) for Android.

I don't have an Apple Developer account to describe how to set up Apple Push Notification Service (APNS) for iOS. But you can follow this guide, provided by Enrico Rossini: MAUI Push Notifications using Azure Notification Hub for iOS

Setting up Azure Notification Hubs

Step 1: Creation of the Notification Hub

Start by creating a new Azure Notification Hub in the Azure portal:

  1. Navigate to the Azure portal.
  2. Click on ‘Create a resource’.
  3. In the search box, type ‘Notification Hub’ and click on it.
  4. Enter all the necessary details and click ‘Create’.

Step 2: Configuring the Notification Hub

After creation, configure your newly created Notification Hub:

  1. Go to your Notification Hub and under the ‘Settings’ section, select ‘Access Policies’.
  2. Note down the two connection strings provided.
  3. You'll need these strings when configuring your .NET MAUI project later.

Setting up Windows Notification Service (WNS)

WNS delivers notifications from cloud servers to Windows apps running on Windows 10 and later.

Step 1: Register Your App

  1. Go to the Windows Dev Center's Dashboard, and sign in.
  2. Choose your app from the list of apps.
  3. Click on ‘Product identity’.
  4. Find the ‘Package SID’ value. We will need it later when configuring WNS with Azure.
  5. Click on ‘App management’ and ‘WNS/MPNS’.
  6. Click on App Registration portal. You will be redirected to Azure portal. App Registration portal link
  7. Click on Certificates & secrets
  8. Click on New client secret and create a new secret. Note down the secret value. It is you Security Key. We will need it later when configuring WNS with Azure.

Step 2: Configure WNS with Azure

  1. Go to the Azure portal.
  2. In your Notification Hub, under ‘Settings’, select 'Windows (WNS)'.
  3. Fill in the ‘Package SID’ and ‘Security Key’ details:
    • Package SID: the value you obtained in the previous step. The format is ms-app://<Package SID>.
    • Security Key: the value you obtained in the previous step.
  4. Click ‘Save’.

Setting up Firebase Cloud Messaging (FCM)

FCM enables you to send push notifications to Android devices.

Step 1: Create a Firebase Project

  1. Go to the Firebase console.
  2. Click on ‘Add project’.
  3. Follow the instructions and set up your project.

Step 2: Obtain Server Key

  1. Navigate to ‘Project settings’.
  2. Click on the ‘Cloud Messaging’ tab. You will see ‘Cloud Messaging API (Legacy)Disabled’ message. Click on ‘Manage API in Google Cloud Console’. You will be redirected to Google Cloud Console. Click on ‘Enable’.
  3. Back to Firebase and copy your ‘Server key’.

Step 3: Configure FCM with Azure

  1. Go to the Azure portal.
  2. In your Notification Hub, under ‘Settings’, select 'Google (GCM/FCM)'.
  3. Enter your ‘Server Key’.
  4. Click ‘Save’.

That's it! You now have Azure Notification Hubs integrated with both FCM and WNS.

As a next step, don't forget to start setting up your .NET MAUI project. You can find out how to do that in the second part of this article series. Here is the link to the second part.

Buy Me A Coffee

Related:

Built in authentication for specific pages in Azure App Service

This article describes how to simplify authentication and authorization for specific pages in Azure App Service by writing minimal or no code in your web app.

An unhandled error has occurred. Reload

🗙