UNPKG

@react-native-firebase/messaging

Version:

React Native Firebase - React Native Firebase provides native integration of Firebase Cloud Messaging (FCM) for both Android & iOS. FCM is a cost free service, allowing for server-device and device-device communication. The React Native Firebase Messaging

183 lines 9.7 kB
import './types/internal'; import type { FirebaseApp } from '@react-native-firebase/app'; import { AuthorizationStatus, NotificationAndroidPriority, NotificationAndroidVisibility } from './statics'; import type { Messaging, RemoteMessage, IOSPermissions, AuthorizationStatus as AuthorizationStatusType, NativeTokenOptions, GetTokenOptions, SendErrorEvent } from './types/messaging'; export declare const SDK_VERSION = "26.1.0"; export { AuthorizationStatus, NotificationAndroidPriority, NotificationAndroidVisibility }; /** * Returns the {@link Messaging} instance for the default or given {@link FirebaseApp}. * * @param app - The Firebase `FirebaseApp` to use. When omitted, the default app is used. * @returns The Messaging service instance for that app. */ export declare function getMessaging(app?: FirebaseApp): Messaging; /** * Removes access to an FCM token previously authorized by its scope. */ export declare function deleteToken(messaging: Messaging, tokenOptions?: NativeTokenOptions): Promise<void>; /** * Returns an FCM token for this device. */ export declare function getToken(messaging: Messaging, options?: GetTokenOptions & NativeTokenOptions): Promise<string>; /** * Subscribes to foreground FCM messages. * * @remarks Event delivery uses the legacy native event proxy shared across RN Firebase modules * (not yet migrated to Codegen TurboModule events). Behavior matches pre-v26 releases. */ export declare function onMessage(messaging: Messaging, listener: (message: RemoteMessage) => any): () => void; /** * When the user presses a notification displayed via FCM, this listener will be called if the app * has opened from a background state. * * @remarks Event delivery uses the legacy native event proxy shared across RN Firebase modules * (not yet migrated to Codegen TurboModule events). Behavior matches pre-v26 releases. */ export declare function onNotificationOpenedApp(messaging: Messaging, listener: (message: RemoteMessage) => any): () => void; /** * Called when a new registration token is generated for the device. * * @remarks Event delivery uses the legacy native event proxy shared across RN Firebase modules * (not yet migrated to Codegen TurboModule events). Behavior matches pre-v26 releases. */ export declare function onTokenRefresh(messaging: Messaging, listener: (token: string) => any): () => void; /** * On iOS, messaging permission must be requested by the current application before messages can * be received or sent. * * @deprecated Use {@link https://github.com/zoontek/react-native-permissions react-native-permissions} or * {@link https://docs.expo.dev/versions/latest/sdk/notifications/ expo-notifications} for notification permission * requests instead. These APIs will be removed in a future major release. * See {@link https://github.com/invertase/react-native-firebase/issues/6283 #6283}. */ export declare function requestPermission(messaging: Messaging, iosPermissions?: IOSPermissions): Promise<AuthorizationStatusType>; /** * Returns whether messaging auto initialization is enabled or disabled for the device. */ export declare function isAutoInitEnabled(messaging: Messaging): boolean; /** * Sets whether messaging auto initialization is enabled or disabled for the device. */ export declare function setAutoInitEnabled(messaging: Messaging, enabled: boolean): Promise<void>; /** * 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`. */ export declare function getInitialNotification(messaging: Messaging): Promise<RemoteMessage | 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. */ export declare function getDidOpenSettingsForNotification(messaging: Messaging): Promise<boolean>; /** * Returns whether the root view is headless or not. */ export declare function getIsHeadless(messaging: Messaging): Promise<boolean>; /** * 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, native registration skips UIKit `registerForRemoteNotifications` * (main-thread wedge risk) and may reject with `messaging/registration-timeout` after ~10s. * Use a physical device for real APNs tokens. A second overlapping call rejects the prior * attempt with `messaging/registration-superseded`. See migrating-to-v26 Cloud Messaging — * iOS APNs registration. */ export declare function registerDeviceForRemoteMessages(messaging: Messaging): Promise<void>; /** * Returns a boolean value whether the user has registered for remote notifications via * `registerDeviceForRemoteMessages()`. */ export declare function isDeviceRegisteredForRemoteMessages(messaging: Messaging): boolean; /** * Unregisters the app from receiving remote notifications. */ export declare function unregisterDeviceForRemoteMessages(messaging: Messaging): Promise<void>; /** * Returns the APNs device token on iOS. * * @remarks **iOS only.** Returns `null` when no token is available. There is no firebase-js-sdk * modular equivalent — web push uses a different token lifecycle. */ export declare function getAPNSToken(messaging: Messaging): Promise<string | null>; /** * Sets the APNs device token received by the application delegate. * * @remarks **iOS only.** `type` must be `'prod'`, `'sandbox'`, or `'unknown'`. */ export declare function setAPNSToken(messaging: Messaging, token: string, type?: string): Promise<void>; /** * Returns a `AuthorizationStatus` as to whether the user has messaging permission for this app. * * @deprecated Use {@link https://github.com/zoontek/react-native-permissions react-native-permissions} or * {@link https://docs.expo.dev/versions/latest/sdk/notifications/ expo-notifications} for notification permission * requests instead. These APIs will be removed in a future major release. * See {@link https://github.com/invertase/react-native-firebase/issues/6283 #6283}. */ export declare function hasPermission(messaging: Messaging): Promise<AuthorizationStatusType>; /** * Called when the FCM server deletes pending messages. * * @remarks Event delivery uses the legacy native event proxy shared across RN Firebase modules * (not yet migrated to Codegen TurboModule events). Behavior matches pre-v26 releases. */ export declare function onDeletedMessages(messaging: Messaging, listener: () => void): () => void; /** * When sending a `RemoteMessage`, this listener is called when the message has been sent to FCM. */ export declare function onMessageSent(messaging: Messaging, listener: (messageId: string) => any): () => void; /** * When sending a `RemoteMessage`, this listener is called when an error is thrown and the * message could not be sent. * * @remarks Event delivery uses the legacy native event proxy shared across RN Firebase modules * (not yet migrated to Codegen TurboModule events). Behavior matches pre-v26 releases. */ export declare function onSendError(messaging: Messaging, listener: (evt: SendErrorEvent) => any): () => void; /** * Set a message handler function which is called when the app is in the background or terminated. * * @remarks Event delivery uses the legacy native event proxy shared across RN Firebase modules * (not yet migrated to Codegen TurboModule events). Behavior matches pre-v26 releases. */ export declare function setBackgroundMessageHandler(messaging: Messaging, handler: (message: RemoteMessage) => Promise<any>): void; /** * Set a handler function which is called when the `${App Name} notifications settings` * link in iOS settings is clicked. */ export declare function setOpenSettingsForNotificationsHandler(messaging: Messaging, handler: (message: RemoteMessage) => any): void; /** * Send a new `RemoteMessage` to the FCM server. */ export declare function sendMessage(messaging: Messaging, message: RemoteMessage): Promise<void>; /** * Apps can subscribe to a topic, which allows the FCM server to send targeted messages to only those * devices subscribed to that topic. */ export declare function subscribeToTopic(messaging: Messaging, topic: string): Promise<void>; /** * Unsubscribe the device from a topic. */ export declare function unsubscribeFromTopic(messaging: Messaging, topic: string): Promise<void>; /** * Returns a boolean whether message delivery metrics are exported to BigQuery. */ export declare function isDeliveryMetricsExportToBigQueryEnabled(messaging: Messaging): boolean; /** * Returns a boolean whether message delegation is enabled. Android only, always returns false on iOS. */ export declare function isNotificationDelegationEnabled(messaging: Messaging): boolean; /** * Sets whether message notification delegation is enabled or disabled. */ export declare function setNotificationDelegationEnabled(messaging: Messaging, enabled: boolean): Promise<void>; /** * Checks if all required APIs exist in the browser. */ export declare function isSupported(messaging: Messaging): Promise<boolean>; /** * Sets whether message delivery metrics are exported to BigQuery is enabled or disabled. */ export declare function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging: Messaging, enabled: boolean): Promise<void>; export type { Messaging, RemoteMessage, MessagePriority, FcmOptions, NativeTokenOptions, GetTokenOptions, Notification, NotificationIOSCriticalSound, IOSPermissions, SendErrorEvent, } from './types/messaging'; //# sourceMappingURL=index.d.ts.map