A comprehensive .NET MAUI library for implementing cross-platform push notifications using Azure Notification Hubs. This solution supports multiple push notification services including APNS (Apple Push Notification Service), FCM (Firebase Cloud Messaging), and WNS (Windows Notification Service).
This library provides a unified, platform-specific implementation for push notifications in .NET MAUI applications, leveraging Azure Notification Hubs as the central messaging service. It abstracts the complexity of platform-specific push notification implementations while maintaining full control over notification handling.
- Purpose: Provides the foundational interfaces, base classes, and shared functionality for push notifications
- Key Components:
INotificationRegistrationService- Core registration interfaceNotificationRegistrationServiceBase- Base implementation for platform-specific servicesPushMessages- Static event system for notification handlingRegisterDeviceMessage- Data structure for device registration- Azure Notification Hub client configuration
- Purpose: Apple Push Notification Service implementation for iOS and Mac Catalyst
- Platforms: iOS 15.0+, Mac Catalyst 15.0+
- Key Components:
- Platform-specific
NotificationRegistrationServiceimplementations UserNotificationDelegatefor handling notification eventsAppDelegateHelpersfor easy integration into AppDelegate
- Platform-specific
- Purpose: Firebase Cloud Messaging implementation for Android
- Platforms: Android API 21+
- Dependencies: Xamarin.Firebase.Messaging
- Key Components:
NotificationRegistrationServicewith Google Play Services validation and Android device ID managementFCMMessagingServicefor handling incoming push notifications with configurable notification channels- Built-in permission checking utilities
- Note: This project is in progress.
- Purpose: Windows Notification Service implementation for Windows
- Platforms: Windows 10.0.17763.0+
- Purpose: Demonstrates how to integrate and use the push notification libraries
- Platforms: All supported platforms (Android, iOS, Mac Catalyst, Windows)
Add references to the required projects in your MAUI application:
<PackageReference Include="MobileNomad.MAUI.PushNotifications.Core" Version="1.0.0" />
<PackageReference Include="MobileNomad.MAUI.PushNotifications.APNS" Version="1.0.1" />
<PackageReference Include="MobileNomad.MAUI.PushNotifications.FCM" Version="1.0.2" />
Configure the notification services in your MauiProgram.cs:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.SetupNotificationsCore(azureConnectionString, hubName)
.SetupNotificationsFCM() // For Android
.SetupNotificationsAPNS(); // For iOS/Mac Catalyst
return builder.Build();
}
}
You'll need:
- Azure Notification Hub connection string
- Hub name
- Platform-specific credentials (APNS certificates, FCM server key, etc.)
- Add notification setup to your
AppDelegate:
using MobileNomad.MAUI.PushNotifications.APNS;
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
AppDelegateHelpers.NotificationFinishedLaunching(this);
return base.FinishedLaunching(application, launchOptions);
}
}
- Then in the register for remote notifications event, use the received token to register for notifications
then register the device. You will need a reference to the
INotificationRegistrationServiceto call the registration method:
[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
public void RegisteredForRemoteNotificationsWithDeviceToken(UIApplication application, NSData deviceToken)
{
var message = AppDelegateHelpers.GetRegisterDeviceMessage(deviceToken);
_notificationRegistrationService.RegisterDevice(message);
}
- Ensure there is a entitlements.plist file with the push notifications entitlement
-
Ensure your
google-services.jsonfile is included in the Android platform folder. -
Add the following to the project file to load the
google-services.jsonfile:
<ItemGroup>
<GoogleServicesJson Include="Platforms\Android\google-services.json" />
</ItemGroup>
- Ensure the
AndroidManifest.xmlhas the following permissions:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
- On the
App.xaml.csfile, in the OnStart event, you can ask the user for notificaiton permissions. The library does have a default implementation to request permissions. You can use it, or provide your own implementation to request permissions. Like with iOS and MacCatalyst, you will need to get a reference to the Android implementation ofINotificationRegistrationServiceto register the device.
#if ANDROID
var permissionStatus = await PermissionChecker.CheckPermissions();
if (permissionStatus == PermissionStatus.Granted)
{
var message = new RegisterDeviceMessage();
_notificationRegistrationService.RegisterDevice(message);
}
#endif
- If required, override the default notificaiton channel Id and channel name.
FCMMessagingService.DefaultChannelId = "some id value";
FCMMessagingService.ChannelName = "some name value";
- Cross-Platform: Single API for all supported platforms
- Azure Integration: Built specifically for Azure Notification Hubs
- Event-Driven: Uses static event system for notification handling
- Modular: Platform-specific implementations can be included as needed
- Type-Safe: Strongly-typed message and response objects
- App initializes with Azure Notification Hub credentials
- Platform-specific services register device tokens
- Azure Notification Hub manages device registrations
- Incoming notifications are handled by platform delegates
- Events are raised through the
PushMessagesstatic class
- .NET 9.0
- .NET MAUI
- Azure Notification Hub service
- Platform-specific push notification credentials
- Android: API 21+ (via FCM)
- iOS: 15.0+ (via APNS)
- Mac Catalyst: 15.0+ (via APNS)
- Windows: 10.0.17763.0+ (via WNS - implementation still in progress)
- Microsoft.Maui.Controls 9.0.50
- Microsoft.Azure.NotificationHubs 4.2.0
- Xamarin.Firebase.Messaging 124.1.0.1 (Android only)
The included sample application demonstrates:
- Proper service configuration
- Device registration
- Notification handling
- Cross-platform compatibility
Run the sample to see the push notification system in action across different platforms.