Push Notification in MAUI (iOS)


Understanding Push NotificationPush notifications are messages that are delivered to a user's device from a server or a cloud service. These notifications appear on the device's notification tray and can contain text, images, or even actions for the user to take. They serve as a direct channel of communication between the app and the user, enabling real-time updates, reminders, and user engagement.

Setting Up Push Notifications in .NET MAUI for iOS:

Important: Push notification seems not working in simulator. we cannot get registration token. But we can deploy MAUI app to a physical device. from that, Push Notification will work. There are two ways to do that.

    1. Use Hot Restart.

    2. Plug in your iOS device in a MAC, then use iOS remote devices in Visual Studio to deploy your app to physical device.

You need to have a MAC to build your app.

To enable push notifications in your .NET MAUI app for iOS, you need to follow a series of steps:

    1. Go to Certificates, Identifiers & Profiles - Apple Developer (you must have apple developer account)

    2. Create a Certificate: visit Create Developer ID certificates - Create certificates - Account - Help - Apple Developer for more details.


    Keep in mind that Apple development is used in Development mode. Apple Distribution is used for testing your app in TestFlight or submit on App Store.

    Once a Certificate is created, download and install it by double click on downloaded profile.   

    To check whether it is downloaded, open Keychain Access on MAC select my certificate tab. your certificate would be displayed. 

    3. Create an Identifier:

        - Press '+' or Register and App ID


        - Choose App IDs.

        - Choose App.


        - Enter a Description and the Bundle ID (which must match your application Id). Select the capabilities that your app requires.     

        - Create a Profile:

        There are two options that you have to focus on is Ad Hoc and App Store. If you want to limit number of registered devices, choose Ad Hoc. 

    4. Create a APNs Key: It's used for push notification.

        


    5. Create your app in Firebase Console:

        - Create or Open existing Project.

        - Create an App.

        - Download GoogleService-info.plist

        - Upload APNs Key: Open Project Settings => select Cloud Messaging tab, then scroll down you can see your iOS app.

        - Click upload your APNs Key created from Apple portal.
        


        You will find Key ID from Key, then click on your Key. Team ID is displayed on the top right.
    
    6. Implement MAUI code.

    - Install require Nuget Package: Run dotnet add package Plugin.Firebase in Developer PowerShell or Window Terminal.

    - Add GoogleService-info.plist in Platform/iOS folder.

    - Add these following code in .csproj file.

    - Create Entitlements.plist in Platform/iOS folder with value like:

    - Add these following code in Info.plist file:

    - Change AppDelegate.cs like this:

    - Create UserNotificationCenterDelegate.cs in the same AppDelegate.cs folder:

    Send Test Notification:

    1. Create your campaign:

    2. Select Firebase Notification messages:

    

    3. Enter your title and body.


    4. Add an FCM registration token that is generated in the first launch:


    You can write it in debug console and then get it:

    After doing more complex steps above, you will receive a push notification in your device. You can visit my repo here to get a sample.

    References:

    - Docs/Firebase_MAUI_iOS_push_notification.md at main · michalpr/Docs (github.com)

    - .NET MAUI Tutorial | Xamarin Coding Tutorial | .NET MAUI Blog - .NET MAUI Samples : Implement Push Notification In .NET MAUI (iOS)