Jump to top

messaging

interface

The Firebase Messaging service interface.

This module is available for the default app only.

Example

Get the Messaging service for the default app:

const defaultAppMessaging = firebase.messaging();

Properties

isAutoInitEnabled

</>

Returns whether messaging auto initialization is enabled or disabled for the device.

isAutoInitEnabled: boolean;

isDeviceRegisteredForRemoteMessages

</>

Returns a boolean value whether the user has registered for remote notifications via registerDeviceForRemoteMessages().

isDeviceRegisteredForRemoteMessages: boolean;

Methods

deleteToken

</>

Removes access to an FCM token previously authorized by it's scope. Messages sent by the server to this token will fail.

deleteToken(options?: NativeTokenOptions): Promise<void>;

experimentalSetDeliveryMetricsExportedToBigQueryEnabled

</>

Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By default, message delivery metrics are not exported to BigQuery. Use this method to enable or disable the export at runtime.

experimentalSetDeliveryMetricsExportedToBigQueryEnabled(): void;

getAPNSToken

</>

On iOS, it is possible to get the users APNs token. This may be required if you want to send messages to your iOS devices without using the FCM service.

getAPNSToken(): Promise<string | null>;

getDidOpenSettingsForNotification

</>

When the app is opened from iOS notifications settings from a quit state, this method will return true or false if the app was opened via another method.

getDidOpenSettingsForNotification(): Promise<boolean>;

getInitialNotification

</>

When a notification from FCM has triggered the application to open from a quit state, this method will return a RemoteMessage containing the notification data, or null if the app was opened via another method.

getInitialNotification(): Promise<RemoteMessage | null>;

getIsHeadless

</>

Returns whether the root view is headless or not i.e true if the app was launched in the background (for example, by data-only cloud message)

getIsHeadless(): Promise<boolean>;

getToken

</>

Returns an FCM token for this device. Optionally you can specify a custom options to your own use-case.

getToken(options?: ): Promise<string>;

hasPermission

</>

Returns a AuthorizationStatus as to whether the user has messaging permission for this app.

hasPermission(): Promise<AuthorizationStatus>;

isSupported

</>

Checks if all required APIs exist in the browser.

isSupported(): Promise<boolean>;

onDeletedMessages

</>

Called when the FCM server deletes pending messages. This may be due to:

onDeletedMessages(listener: () => void): () => void;

onMessage

</>

When any FCM payload is received, the listener callback is called with a RemoteMessage.

onMessage(listener: (message: RemoteMessage) => any): () => void;

onMessageSent

</>

When sending a RemoteMessage, this listener is called when the message has been sent to FCM.

onMessageSent(listener: (messageId: string) => any): () => void;

onNotificationOpenedApp

</>

When the user presses a notification displayed via FCM, this listener will be called if the app has opened from a background state.

onNotificationOpenedApp(listener: (message: RemoteMessage) => any): () => void;

onSendError

</>

When sending a RemoteMessage, this listener is called when an error is thrown and the message could not be sent.

onSendError(listener: (evt: SendErrorEvent) => any): () => void;

onTokenRefresh

</>

Called when a new registration token is generated for the device. For example, this event can happen when a token expires or when the server invalidates the token.

onTokenRefresh(listener: (token: string) => any): () => void;

registerDeviceForRemoteMessages

</>

On iOS, if your app wants to receive remote messages from FCM (via APNs), you must explicitly register with APNs if auto-registration has been disabled.

registerDeviceForRemoteMessages(): Promise<void>;

requestPermission

</>

On iOS, messaging permission must be requested by the current application before messages can be received or sent.

requestPermission(permissions?: IOSPermissions): Promise<AuthorizationStatus>;

sendMessage

</>

Send a new RemoteMessage to the FCM server.

sendMessage(message: RemoteMessage): Promise<void>;

setAPNSToken

</>

On iOS, This method is used to set the APNs Token received by the application delegate. Note that the token is expected to be a hexadecimal string, as it is an NSData type in the underlying native firebase SDK, and raw data may only be passed as a string if it is hex encoded. Calling code is responsible for correct encoding, you should verify by comparing the results of getAPNSToken() with your token parameter to make sure they are equivalent

setAPNSToken(token: string, type?: undefined | string): Promise<void>;

setAutoInitEnabled

</>

Sets whether auto initialization for messaging is enabled or disabled.

setAutoInitEnabled(enabled: boolean): Promise<void>;

setBackgroundMessageHandler

</>

Set a message handler function which is called when the app is in the background or terminated. In Android, a headless task is created, allowing you to access the React Native environment to perform tasks such as updating local storage, or sending a network request.

setBackgroundMessageHandler(handler: (message: RemoteMessage) => Promise<any>): void;

setDeliveryMetricsExportToBigQuery

</>

Sets whether message delivery metrics are exported to BigQuery is enabled or disabled.

setDeliveryMetricsExportToBigQuery(enabled: boolean): Promise<void>;

setOpenSettingsForNotificationsHandler

</>

Set a handler function which is called when the ${App Name} notifications settings link in iOS settings is clicked.

setOpenSettingsForNotificationsHandler(handler: (message: RemoteMessage) => any): void;

subscribeToTopic

</>

Apps can subscribe to a topic, which allows the FCM server to send targeted messages to only those devices subscribed to that topic.

subscribeToTopic(topic: string): Promise<void>;

unregisterDeviceForRemoteMessages

</>

Unregisters the app from receiving remote notifications.

unregisterDeviceForRemoteMessages(): Promise<void>;

unsubscribeFromTopic

</>

Unsubscribe the device from a topic.

unsubscribeFromTopic(topic: string): Promise<void>;

Statics

AuthorizationStatus

</>
messaging.AuthorizationStatus: ;

NotificationAndroidPriority

</>
messaging.NotificationAndroidPriority: ;

NotificationAndroidVisibility

</>
messaging.NotificationAndroidVisibility: ;