Firebase.Messaging.FirebaseMessaging

Firebase Cloud Messaging API.

Summary

Firebase Cloud Messaging allows you to send data from your server to your users' devices, and receive messages from devices on the same connection if you're using a XMPP server.

The FCM service handles all aspects of queueing of messages and delivery to client applications running on target devices.

Events

MessageReceived
static System.EventHandler< MessageReceivedEventArgs >
Called on the client when a message arrives.
TokenReceived
static System.EventHandler< TokenReceivedEventArgs >
Called on the client when a registration token message arrives.

Properties

TokenRegistrationOnInitEnabled
static bool
Enable or disable token registration during initialization of Firebase Cloud Messaging.

Public static functions

RequestPermissionAsync()
Displays a prompt to the user requesting permission to display notifications.
Send(FirebaseMessage message)
void
Send an upstream ("device to cloud") message.
Subscribe(string topic)
void
Subscribe to receive all messages to the specified topic.
SubscribeAsync(string topic)
Subscribe to receive all messages to the specified topic.
Unsubscribe(string topic)
void
Unsubscribe from a topic.
UnsubscribeAsync(string topic)
Unsubscribe from a topic.

Events

MessageReceived

static System.EventHandler< MessageReceivedEventArgs > MessageReceived

Called on the client when a message arrives.

TokenReceived

static System.EventHandler< TokenReceivedEventArgs > TokenReceived

Called on the client when a registration token message arrives.

Properties

TokenRegistrationOnInitEnabled

static bool TokenRegistrationOnInitEnabled

Enable or disable token registration during initialization of Firebase Cloud Messaging.

This token is what identifies the user to Firebase, so disabling this avoids creating any new identity and automatically sending it to Firebase, unless consent has been granted.

If this setting is enabled, it triggers the token registration refresh immediately. This setting is persisted across app restarts and overrides the setting "firebase_messaging_auto_init_enabled" specified in your Android manifest (on Android) or Info.plist (on iOS).

By default, token registration during initialization is enabled.

The registration happens before you can programmatically disable it, so if you need to change the default, (for example, because you want to prompt the user before FCM generates/refreshes a registration token on app startup), add to your application’s manifest:

<meta-data android:name="firebase_messaging_auto_init_enabled"
android:value="false" />

or on iOS to your Info.plist:

<key>FirebaseMessagingAutoInitEnabled</key>
<false/>

Public static functions

RequestPermissionAsync

System.Threading.Tasks.Task RequestPermissionAsync()

Displays a prompt to the user requesting permission to display notifications.

The permission prompt only appears on iOS. If the user has already agreed to allow notifications, no prompt is displayed and the returned future is completed immediately.

A future that completes when the notification prompt has been dismissed.

Send

void Send(
  FirebaseMessage message
)

Send an upstream ("device to cloud") message.

You can only use the upstream feature if your FCM implementation uses the XMPP-based Cloud Connection Server. The current limits for max storage time and number of outstanding messages per application are documented in the FCM Developers Guide.

Details
Parameters
message
The message to send upstream.

Subscribe

void Subscribe(
  string topic
)

Subscribe to receive all messages to the specified topic.

Subscribes an app instance to a topic, enabling it to receive messages sent to that topic.

Call this function from the main thread. FCM is not thread safe.

Details
Parameters
topic
The name of the topic to subscribe. Must match the following regular expression: [a-zA-Z0-9-_.~%]{1,900}.

SubscribeAsync

System.Threading.Tasks.Task SubscribeAsync(
  string topic
)

Subscribe to receive all messages to the specified topic.

Subscribes an app instance to a topic, enabling it to receive messages sent to that topic.

Call this function from the main thread. FCM is not thread safe.

Details
Parameters
topic
The name of the topic to subscribe. Must match the following regular expression: [a-zA-Z0-9-_.~%]{1,900}.

Unsubscribe

void Unsubscribe(
  string topic
)

Unsubscribe from a topic.

Unsubscribes an app instance from a topic, stopping it from receiving any further messages sent to that topic.

Call this function from the main thread. FCM is not thread safe.

Details
Parameters
topic
The name of the topic to unsubscribe from. Must match the following regular expression: [a-zA-Z0-9-_.~%]{1,900}.

UnsubscribeAsync

System.Threading.Tasks.Task UnsubscribeAsync(
  string topic
)

Unsubscribe from a topic.

Unsubscribes an app instance from a topic, stopping it from receiving any further messages sent to that topic.

Call this function from the main thread. FCM is not thread safe.

Details
Parameters
topic
The name of the topic to unsubscribe from. Must match the following regular expression: [a-zA-Z0-9-_.~%]{1,900}.

Send feedback about...

Need help? Visit our support page.