Skip to content
Food and Coding at NorthEnd Coffee shop, Banani, Dhaka

Configure azure notification hub for ios android and web

October 16, 2024 cloud jonathansblog

To configure Azure Notification Hub for iOS, Android, and Web push notifications, you need to follow platform-specific steps to integrate Azure Notification Hub with each type of platform.

1. Configure for Android (FCM)

  • Create a Firebase Project:
    • Go to the Firebase Console.
    • Create a new project and configure Firebase Cloud Messaging (FCM).
  • Generate Firebase Credentials:
    • Go to Project Settings > Cloud Messaging and generate a new Server Key (needed for Azure Notification Hub).
    • Download the google-services.json file, which is needed for your Android app.
  • Configure Azure Notification Hub:
    • In the Azure Portal, navigate to Notification Hubs.
    • Create a new Notification Hub or select an existing one.
    • Under Settings, go to Push Notification ServicesGoogle (GCM/FCM).
    • Enter the Firebase Server Key (from Firebase console).
  • Configure the Android App:
    • Add the google-services.json file to your Android app.
    • Set up the FCM library in your Android app to register with FCM.

2. Configure for iOS (APNs)

  • Create an Apple Developer Account:
  • Generate APNs Credentials:
    • Create an App ID for your iOS app in Certificates, Identifiers & Profiles.
    • Under Identifiers, select your app ID and enable Push Notifications.
    • Create an APNs Key or APNs Certificate (use .p8 or .pem file).
  • Configure Azure Notification Hub:
    • In the Azure Portal, navigate to your Notification Hub.
    • Under Push Notification Services, go to Apple (APNs).
    • Upload the APNs Key (.p8 file) or Certificate (.pem file) and enter the Key ID, Team ID, and other credentials.
  • Configure the iOS App:
    • Add Push Notification capabilities in Xcode.
    • Integrate the Apple Push Notification Service (APNs) library into your iOS app.
    • Register your app with APNs and ensure the device receives push tokens.

3. Configure for Web Push (PWA)

  • Generate VAPID Keys:
    • Use a library like web-push to generate VAPID (Voluntary Application Server Identification) keys.
npm install web-push -g
web-push generate-vapid-keys
  • This generates public and private VAPID keys.
  • Configure Azure Notification Hub:
    • In the Azure Portal, navigate to your Notification Hub.
    • Under Push Notification Services, go to Web (WNS, Chrome, etc.).
    • Enter the VAPID public and private keys generated earlier.
  • Configure the Service Worker:
    • Create a Service Worker in your web app to listen for push notifications.
    • Register the service worker in your Next.js (or any web) app:jsCopy codenavigator.serviceWorker.register('/sw.js');
    • In the service worker (sw.js), handle push events and display notifications:
self.addEventListener('push', function(event) {
  const data = event.data.json();
  self.registration.showNotification(data.title, {
    body: data.body,
    icon: data.icon,
  });
});
  • Send the Subscription to Azure Notification Hub:
    • When a user subscribes to notifications in the browser, send the subscription object to your backend.
    • From your backend (Laravel or Node.js), use Azure Notification Hubs to send web push notifications.

You must be <a href="https://jonathansblog.co.uk/wp-login.php?redirect_to=https%3A%2F%2Fjonathansblog.co.uk%2Fconfigure-azure-notification-hub-for-ios-android-and-web">logged in</a> to post a comment.