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;
        onRegistered(
            nextOrObserver: NextFn<string> | Observer<string>,
        ): Unsubscribe;
        onSendError(listener: (evt: SendErrorEvent) => any): () => void;
        onTokenRefresh(listener: (token: string) => any): () => void;
        onUnregistered(
            nextOrObserver: NextFn<string> | Observer<string>,
        ): Unsubscribe;
        register(options?: RegisterOptions): Promise<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>;
        unregister(): 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>

      Firebase JS 12.14+, Android Messaging 25.1+, and Apple 12.18+ deprecated FCM token APIs (getToken, deleteToken, onTokenRefresh) in favor of FID registration (unregister / onUnregistered). Prefer Messaging.unregister and Messaging.onUnregistered after opting in to Installation ID messaging. Token APIs still work while the FID flag is off.

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

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

      Parameters

      Returns Promise<string>

      Firebase JS 12.14+, Android Messaging 25.1+, and Apple 12.18+ deprecated FCM token APIs (getToken, deleteToken, onTokenRefresh) in favor of FID registration (register / onRegistered). Prefer Messaging.register and Messaging.onRegistered after opting in to Installation ID messaging. Token APIs still work while the FID flag is off.

    • 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

    • Subscribes to Firebase Installation ID (FID) registration events.

      Fires for explicit register(), auto-init at startup, and installation-id rotation. While still registered, a new subscriber receives the cached FID immediately; later events still fire.

      Requires Installation ID messaging to be enabled. See Messaging.register.

      Parameters

      • nextOrObserver: NextFn<string> | Observer<string>

        A next function or Observer called with the FID.

      Returns Unsubscribe

    • 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

      Firebase JS 12.14+, Android Messaging 25.1+, and Apple 12.18+ deprecated FCM token APIs (getToken, deleteToken, onTokenRefresh) in favor of FID registration (register / onRegistered). Prefer Messaging.register and Messaging.onRegistered after opting in to Installation ID messaging. Token APIs still work while the FID flag is off.

    • Subscribes to Firebase Installation ID (FID) unregistration events.

      Fires only after a successful unregister(), with that FID. Does not replay to a late subscriber.

      Requires Installation ID messaging to be enabled. See Messaging.register.

      Parameters

      • nextOrObserver: NextFn<string> | Observer<string>

        A next function or Observer called with the unregistered FID.

      Returns Unsubscribe

    • Registers the app instance with FCM using its Firebase Installation ID (FID).

      Requires Installation ID messaging to be enabled (Android meta-data firebase_messaging_installation_id_enabled, iOS Info.plist FirebaseMessagingInstallationIdEnabled, or Expo plugin installationIdEnabled: true). Does not call registerDeviceForRemoteMessages / APNs registration.

      Web-only RegisterOptions fields are ignored on React Native.

      Parameters

      • Optionaloptions: RegisterOptions

        Optional web-parity options (ignored on native).

      Returns Promise<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.

      On ARM64 iOS Simulator, UIKit registration is skipped intentionally so the main thread cannot wedge; the call may reject with messaging/registration-timeout after ~10s and will not produce a real APNs token. Use a physical device for end-to-end push. Overlapping calls reject the earlier attempt with messaging/registration-superseded. requestPermission's APNs side-effect is also skipped on ARM64 Simulator but that Promise still resolves with AuthorizationStatus (it does not reject with these codes).

      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, 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>

    • Unregisters the app instance from FCM so the current Firebase Installation ID is no longer active for receiving messages.

      Requires Installation ID messaging to be enabled. See Messaging.register.

      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.