MAUI: Push notification for iOS platform

Sreejith Sreenivasan 611 Reputation points
2023-11-06T15:18:50.8233333+00:00

I am using Plugin.Firebase and Plugin.Firebase.Crashlytics packages for implementing push notification in my MAUI application. I referred this blog and it was working fine on the Android platform. Now I am implementing it for the iOS platform.

I have done below set up on iOS platform:

  1. I have added Push Notification service into the app’s identifier on apple developer website.
  2. Created a new provisioning profile, install it on the device and bind it to the project settings.
  3. Created a new key.(.P8 file) and uploaded it into the FCM console. When uploading the key, provided the Team Id and Key Id.

Pending Set UP

  1. I need to enable the Remote Notification on Info.plist file. It was under Capabilities tab on Xamarin Forms application. But on MAUI there is no such tab.

User's image

  1. I need to enable the Push Notifications in the Entitlements.plist, but that file is not found on the MAUI iOS folder. Should I need to create it and How can I create such type of files?

After all these 2 pending set up, is FCM token will generate or anything else is pending to do on iOS platform?

Below is my FCM token function and it was working fine for Android platform:

private async void GetToken()
{
    await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
    var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
    Preferences.Default.Set("devicefcmtoken", token);
    Console.WriteLine($"FCM token::>> {token}");
}
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,184 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 23,391 Reputation points Microsoft Vendor
    2023-11-08T04:55:55.18+00:00

    Hello,

    As you @ Sreejith Sreenivasan said, you solved the problem. Thanks for your sharing.

    And you can manually edit the Info.plist and add the following key/value pair to enable the Remote Notification:

    <key>UIBackgroundModes</key>
        <array>
            <string>remote-notification</string>
        </array>
    

    For adding a new entitlements file, you added a new XML file named Entitlements.plist to the Platforms\iOS folder of your app project. Then add the following XML to the file. And then add Push notifications to the Entitlements.plist.

    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>aps-environment</key>
        <string>development</string>
    </dict>
    </plist>
    

    For more details, you can see iOS entitlements - .NET MAUI | Microsoft Learn

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful