Plugin.Firebase.CloudMessaging 4.0.1

dotnet add package Plugin.Firebase.CloudMessaging --version 4.0.1
 
NuGet\Install-Package Plugin.Firebase.CloudMessaging -Version 4.0.1
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Firebase.CloudMessaging" Version="4.0.1" />
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plugin.Firebase.CloudMessaging" Version="4.0.1" />
 
Directory.Packages.props
<PackageReference Include="Plugin.Firebase.CloudMessaging" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Plugin.Firebase.CloudMessaging --version 4.0.1
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Plugin.Firebase.CloudMessaging, 4.0.1"
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Plugin.Firebase.CloudMessaging@4.0.1
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Plugin.Firebase.CloudMessaging&version=4.0.1
 
Install as a Cake Addin
#tool nuget:?package=Plugin.Firebase.CloudMessaging&version=4.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Cloud Messaging

Firebase Cloud Messaging offers a broad range of messaging options and capabilities. I invite you to read the following documentation to have a better understanding about notification messages and data messages and what you can do with them using FCM's options.

Installation

Nuget

NuGet

Install-Package Plugin.Firebase.CloudMessaging

Setup

  • Follow the instructions for the basic setup
  • Enable Cloud Messaging at your project in the Firebase Console
  • Add the following line of code after calling CrossFirebase.Initialize():
#if IOS
 FirebaseCloudMessagingImplementation.Initialize();
#endif
  • Make sure the device is able to receive cloud messages and the user has granted the permissions for it:
 CrossFirebaseCloudMessaging.Current.CheckIfValid()

iOS specifics

 <key>aps-environment</key>
 <string>development</string>
  • For testing launch the app without the debugger, otherwise the push notification may not be received
  • For more specific instructions take a look at the official Firebase documentation

Android specifics

  • Add the following code snippet to the <application> tag in your apps AndroidManifest.xml:
 <receiver
 android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
 android:exported="false" />
 <receiver
 android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
 android:exported="true"
 android:permission="com.google.android.c2dm.permission.SEND">
 <intent-filter>
 <action android:name="com.google.android.c2dm.intent.RECEIVE" />
 <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
 <category android:name="${applicationId}" />
 </intent-filter>
 </receiver>
  • Call FirebaseCloudMessagingImplementation.OnNewIntent(intent) from MainActivity.OnCreate(...) and MainActivity.OnNewIntent(...)
  • Create a notification channel and set the ChannelId to FirebaseCloudMessagingImplementation:
 private void CreateNotificationChannel()
 {
 var channelId = $"{Application.Context.PackageName}.general";
 var notificationManager = (NotificationManager) Application.Context.GetSystemService(Context.NotificationService);
 var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
 notificationManager.CreateNotificationChannel(channel);
 FirebaseCloudMessagingImplementation.ChannelId = channelId;
 }
Customize local push notifications

Local push notifications are shown by default in a specific way, but you have the following two options to customize this behavior:

Overriding FirebaseCloudMessagingImplementation.NotificationBuilderProvider:
FirebaseCloudMessagingImplementation.NotificationBuilderProvider = notificaion => new NotificationCompat.Builder(context, channelId)
 .SetSmallIcon(Android.Resource.Drawable.SymDefAppIcon)
 .SetContentTitle(notification.Title)
 .SetContentText(notification.Body)
 .SetPriority(NotificationCompat.PriorityDefault)
 .SetAutoCancel(true);
Setting FirebaseCloudMessagingImplementation.ShowLocalNotificationAction:
FirebaseCloudMessagingImplementation.ShowLocalNotificationAction = notification => {
 var intent = PackageManager.GetLaunchIntentForPackage(PackageName);
 intent.PutExtra(FirebaseCloudMessagingImplementation.IntentKeyFCMNotification, notification.ToBundle());
 intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
 var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.Immutable | PendingIntentFlags.UpdateCurrent);
 var builder = new NotificationCompat.Builder(context, channelId)
 .SetSmallIcon(Android.Resource.Drawable.SymDefAppIcon)
 .SetContentTitle(notification.Title)
 .SetContentText(notification.Body)
 .SetPriority(NotificationCompat.PriorityDefault)
 .SetAutoCancel(true);
 var notificationManager = (NotificationManager) GetSystemService(NotificationService);
 notificationManager.Notify(123, builder.SetContentIntent(pendingIntent).Build());
};

You can find more specific instructions for android at the official Firebase documentation

Usage

Take a look at the documentation for the AdamE.Firebase.iOS.CloudMessaging packages, because Plugin.Firebase's code is abstracted but still very similar.

Since code should be documenting itself you can also take a look at the following classes:

Test with curl

curl --location 'https://fcm.googleapis.com/fcm/send' \
--header 'Authorization: key=<your-api-token-from-firebase-console-cloud-messaging-project-settings>' \
--header 'Content-Type: application/json' \
--data '{
 "to" : "<your-device-fcm-token>",
 "collapse_key" : "type_a",
 "mutable_content": true,
 "notification" : {
 "title": "Knock knock",
 "body" : "Who's there?",
 "badge": 1
 },
 "data" : {
 "body" : "body of your notification in data",
 "title": "title of your notification in data",
 "is_silent_in_foreground": "false"
 }
}'
Extra flags
is_silent_in_foreground

Add "is_silent_in_foreground": "true" to the data payload to prevent showing the local push notification. The flag prevents a notification to be generated if the app is in foreground - otherwise the notifications will still be shown. Event CrossFirebaseCloudMessaging.Current.NotificationReceived is still triggered to allow for manual notification handling.

Note: this is a Plugin.Firebase custom field and hence not documented with google FCM documentation.

Troubleshooting

If you are having trouble receiving push notifications on your device, take a look at this helpful https://github.com/TobiasBuchholz/Plugin.Firebase/issues/145#issuecomment-1455182588 by @andyzukunft. Additionally he has created a dedicated project to simplify the demonstration on how Firebase Cloud Messaging works: https://github.com/andyzukunft/Plugin.Firebase/tree/fcm-demo/sample/Fcm

Release notes

  • Version 4.0.1
    • Add iOS action identifier to notification body (PR #547)
  • Version 4.0.0
    • Upgrade baseline to .NET 9+.
  • Version 3.1.2
    • Using AdamE.Firebase.iOS.* minimum version 11
  • Version 3.1.1
    • Fix/iOS notifications not playing sound (PR #352)
  • Version 3.1.0
    • Update to .net8
  • Version 3.0.0
    • Swapped Xamarin.Firebase.iOS.CloudMessaging (native SDK 8.10.0) for AdamE.Firebase.iOS.CloudMessaging (native SDK 10.24.0)
  • Version 2.0.4
    • Add FirebaseCloudMessagingImplementation.ShowLocalNotificationAction (issue #163)
  • Version 2.0.3
    • Enable silent push notifications when the app is in foreground (PR #188)
  • Version 2.0.2
    • Prevent error message when no image is attached to push notifications
  • Version 2.0.1
    • Remove unnecessary UseMaui property from csproj files
    • Readd net6.0 tfm
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. net9.0-android was computed. net9.0-android35.0 is compatible. net9.0-browser was computed. net9.0-ios was computed. net9.0-ios18.0 is compatible. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed.
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Plugin.Firebase.CloudMessaging:

Package Downloads
Plugin.Firebase

The plugin includes cross-platform APIs for Firebase Analytics, Auth, Cloud Messaging, Crashlytics, Dynamic Links, Firestore, Cloud Functions, Remote Config and Storage.

MetaFrm.Maui.Essentials.net8.0

Meta Framework (Multi platform & Meta management)

MetaFrm.Maui.Essentials.net9.0

Meta Framework (Multi platform & Meta management)

MetaFrm.Maui.Essentials.net7.0

Meta Framework (Multi platform & Meta management)

ItEnterprise.Maui.Common

ItEnterprise application core library

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Plugin.Firebase.CloudMessaging:

Repository Stars
Valour-Software/Valour
Valour is bringing communities into the future with unique features, blazing performance, and respect for users.
Version Downloads Last Updated
4.0.1 45,583 3/1/2026
4.0.0 49,546 12/28/2025
3.1.2 281,862 1/16/2025
3.1.1 46,918 11/9/2024
3.1.0 3,141 11/9/2024
3.0.0 89,739 5/29/2024
2.0.4 139,931 11/20/2023
2.0.3 49,671 7/28/2023
2.0.2 29,803 4/11/2023
2.0.1 3,381 3/31/2023
2.0.0 7,387 3/26/2023