React Native Firebase
    Preparing search index...

    The Firebase Messaging service interface.

    This module is available for the default app only.

    interface Messaging {
        app: ReactNativeFirebase.FirebaseApp;
        isAutoInitEnabled: boolean;
        isDeliveryMetricsExportToBigQueryEnabled: boolean;
        isDeviceRegisteredForRemoteMessages: boolean;
        isNotificationDelegationEnabled: boolean;
        deleteToken(options?: NativeTokenOptions): Promise<void>;
        getAPNSToken(): Promise<string | null>;
        getDidOpenSettingsForNotification(): Promise<boolean>;
        getInitialNotification(): Promise<RemoteMessage | null>;
        getIsHeadless(): Promise<boolean>;
        getToken(options?: GetTokenOptions & NativeTokenOptions): Promise<string>;
        hasPermission(): Promise<AuthorizationStatus>;
        isSupported(): Promise<boolean>;
        onDeletedMessages(listener: () => void): () => void;
        onMessage(listener: (message: RemoteMessage) => any): () => void;
        onMessageSent(listener: (messageId: string) => any): () => void;
        onNotificationOpenedApp(
            listener: (message: RemoteMessage) => any,
        ): () => void;
        onSendError(listener: (evt: SendErrorEvent) => any): () => void;
        onTokenRefresh(listener: (token: string) => any): () => void;
        registerDeviceForRemoteMessages(): Promise<void>;
        requestPermission(
            permissions?: IOSPermissions,
        ): Promise<AuthorizationStatus>;
        sendMessage(message: RemoteMessage): Promise<void>;
        setAPNSToken(token: string, type?: string): Promise<void>;
        setAutoInitEnabled(enabled: boolean): Promise<void>;
        setBackgroundMessageHandler(
            handler: (message: RemoteMessage) => Promise<any>,
        ): void;
        setDeliveryMetricsExportToBigQuery(enabled: boolean): Promise<void>;
        setNotificationDelegationEnabled(enabled: boolean): Promise<void>;
        setOpenSettingsForNotificationsHandler(
            handler: (message: RemoteMessage) => any,
        ): void;
        subscribeToTopic(topic: string): Promise<void>;
        unregisterDeviceForRemoteMessages(): Promise<void>;
        unsubscribeFromTopic(topic: string): Promise<void>;
    }

    Hierarchy (View Summary)

    Index

    Methods

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

      Parameters

      • Optionaloptions: NativeTokenOptions

        Options to override senderId (iOS) and appName (android)

      Returns Promise<void>

    • 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.

      You can safely call this method on Android without platform checks. It's a no-op on Android and will promise resolve null.

      Returns Promise<string | null>

    • 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.

      Returns Promise<boolean>

    • 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.

      Returns Promise<RemoteMessage | null>

    • iOS only - 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)

      Returns Promise<boolean>

    • On Web, checks if all required APIs exist in the browser.

      Returns Promise<boolean>

    • On Android, called when the FCM server deletes pending messages.

      Returns an unsubscribe function to stop listening for deleted messages.

      Parameters

      • listener: () => void

        Called when the FCM deletes pending messages.

      Returns () => void

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

      Returns an unsubscribe function to stop listening for new messages.

      This subscriber method is only called when the app is active (in the foreground).

      Parameters

      • listener: (message: RemoteMessage) => any

        Called with a RemoteMessage when a new FCM payload is received from the server.

      Returns () => void

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

      Returns an unsubscribe function to stop listening for sent messages.

      Parameters

      • listener: (messageId: string) => any

        Called when the FCM sends the remote message to FCM.

      Returns () => void

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

      Parameters

      • listener: (message: RemoteMessage) => any

        Called with a RemoteMessage when a notification press opens the application.

      Returns () => void

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

      Returns an unsubscribe function to stop listening for sent errors.

      NOTE: Android only

      Parameters

      Returns () => void

    • 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.

      Returns an unsubscribe function to stop listening for token refresh events.

      This subscriber method is only called when the app is active (in the foreground).

      Parameters

      • listener: (token: string) => any

        Called with a FCM token when the token is refreshed.

      Returns () => void

    • 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.

      You can safely call this method on Android without platform checks. It's a no-op on Android and will promise resolve void.

      Returns Promise<void>

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

      You can safely call this method on Android without platform checks. It's a no-op on Android and will promise resolve AuthorizationStatus.AUTHORIZED.

      Parameters

      Returns Promise<AuthorizationStatus>

    • On iOS, This method is used to set the APNs Token received by the application delegate.

      You can safely call this method on Android without platform checks. It's a no-op on Android and will promise resolve null.

      Parameters

      • token: string

        a hexadecimal string representing your APNS token

      • Optionaltype: string

        optional string specifying 'prod', 'sandbox' or 'unknown' token type

      Returns Promise<void>

    • Sets whether auto initialization for messaging is enabled or disabled.

      Parameters

      • enabled: boolean

        A boolean value to enable or disable auto initialization.

      Returns Promise<void>

    • Set a message handler function which is called when the app is in the background or terminated.

      Parameters

      • handler: (message: RemoteMessage) => Promise<any>

        called with an argument of type messaging.RemoteMessage that must be async and return a Promise

      Returns void

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

      Parameters

      • enabled: boolean

        A boolean value to enable or disable exporting of message delivery metrics to BigQuery.

      Returns Promise<void>

    • Sets whether remote notification delegation to Google Play Services is enabled or disabled.

      Parameters

      • enabled: boolean

        A boolean value to enable or disable remote notification delegation to Google Play Services.

      Returns Promise<void>

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

      Parameters

      Returns void

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

      Parameters

      • topic: string

        The topic name.

      Returns Promise<void>

    • On iOS, unregisters the app from receiving remote notifications.

      You can safely call this method on Android without platform checks. It's a no-op on Android and will promise resolve void.

      Returns Promise<void>

    • Unsubscribe the device from a topic.

      Parameters

      • topic: string

        The topic name.

      Returns Promise<void>

    Properties

    The FirebaseApp this module is associated with

    isAutoInitEnabled: boolean

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

    isDeliveryMetricsExportToBigQueryEnabled: boolean

    Returns whether message delivery metrics are exported to BigQuery.

    isDeviceRegisteredForRemoteMessages: boolean

    On iOS, returns a boolean value whether the user has registered for remote notifications via registerDeviceForRemoteMessages().

    You can safely access this property on Android without platform checks. Android returns true only.

    isNotificationDelegationEnabled: boolean

    Returns whether remote notification delegation to Google Play Services is enabled or disabled.

    You can safely access this property on iOS without platform checks. iOS returns false only.