/* * Copyright (c) 2016-present Invertase Limited */ import { Event, ForegroundServiceTask, InitialNotification, Notification } from './Notification'; import { Trigger } from './Trigger'; import { AndroidChannel, AndroidChannelGroup, NativeAndroidChannel, NativeAndroidChannelGroup, } from './NotificationAndroid'; import { IOSNotificationCategory, IOSNotificationConfig, IOSNotificationPermissions, } from './NotificationIOS'; import { PowerManagerInfo } from './PowerManagerInfo'; import { DisplayedNotification, NotificationSettings, TriggerNotification } from '..'; import type { FcmConfig, FcmRemoteMessage } from '../fcm/types'; export interface Module { /** * API used to cancel all notifications. * * The `cancelAllNotifications` API removes any displayed notifications from the users device and * any pending trigger notifications. * * This method does not cancel Android [Foreground Service](/react-native/android/foreground-service) * notifications. * @param notificationIds An array of notifications IDs. This is automatically generated and returned * when creating a notification, or has been set manually via the `id` property. * * @param tag The tag set when creating the notification. This is only relative to Android. */ cancelAllNotifications(notificationIds?: string[], tag?: string): Promise; /** * API used to cancel any displayed notifications. * * This method does not cancel Android [Foreground Service](/react-native/android/foreground-service) * notifications. */ cancelDisplayedNotifications(notificationIds?: string[]): Promise; /** * API used to cancel any trigger notifications. */ cancelTriggerNotifications(notificationIds?: string[]): Promise; /** * API used to cancel a single notification. * * The `cancelNotification` API removes any displayed notifications or ones with triggers * set for the specified ID. * * This method does not cancel [Foreground Service](/react-native/android/foreground-service) * notifications. * * @param notificationId The unique notification ID. This is automatically generated and returned * when creating a notification, or has been set manually via the `id` property. * * @param tag The tag set when creating the notification. This is only relative to Android. */ cancelNotification(notificationId: string, tag?: string): Promise; /** * API used to cancel a single displayed notification. * * * This method does not cancel [Foreground Service](/react-native/android/foreground-service) * notifications. * * @param notificationId The unique notification ID. This is automatically generated and returned * when creating a notification, or has been set manually via the `id` property. * * @param tag The tag set when creating the notification. This is only relative to Android. */ cancelDisplayedNotification(notificationId: string, tag?: string): Promise; /** * API used to cancel a single trigger notification. * * * @param notificationId The unique notification ID. This is automatically generated and returned * when creating a notification, or has been set manually via the `id` property. */ cancelTriggerNotification(notificationId: string): Promise; /** * API to create and update channels on supported Android devices. * * Creates a new Android channel. Channels are used to collectively assign notifications to * a single responsible channel. Users can manage settings for channels, e.g. disabling sound or vibration. * Channels can be further organized into groups (see `createChannelGroup`). * * By providing a `groupId` property, channels can be assigned to groups created with * [`createChannelGroup`](/react-native/reference/createchannelgroup). * * The channel ID is returned once the operation has completed. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android * @param channel The [`AndroidChannel`](/react-native/reference/androidchannel) interface used to create/update a group. */ createChannel(channel: AndroidChannel): Promise; /** * API to create and update multiple channels on supported Android devices. * * This API is used to perform a single operation to create or update channels. See the * [`createChannel`](/react-native/reference/createchannel) documentation for more information. * * @platform android * @param channels An array of [`AndroidChannel`](/react-native/reference/androidchannel) interfaces. */ createChannels(channels: AndroidChannel[]): Promise; /** * API to create or update a channel group on supported Android devices. * * Creates a new Android channel group. Groups are used to further organize the appearance of your * channels in the settings UI. Groups allow users to easily identify and control multiple * notification channels. * * Channels can be assigned to groups during creation using the * [`createChannel`](/react-native/reference/createchannel) method. * * The channel group ID is returned once the operation has completed. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android * @param channelGroup The [`AndroidChannelGroup`](/react-native/reference/androidchannelgroup) * interface used to create/update a group. */ createChannelGroup(channelGroup: AndroidChannelGroup): Promise; /** * API to create and update multiple channel groups on supported Android devices. * * This API is used to perform a single operation to create or update channel groups. See the * [`createChannelGroup`](/react-native/reference/createchannelgroup) documentation for more information. * * @platform android * @param channelGroups An array of [`AndroidChannelGroup`](/react-native/reference/androidchannelgroup) interfaces. */ createChannelGroups(channelGroups: AndroidChannelGroup[]): Promise; /** * API used to delete a channel by ID on supported Android devices. * * Channels can be deleted using this API by providing the channel ID. Channel information (including * the ID) can be retrieved from the [`getChannels`](/react-native/reference/getchannels) API. * * > When a channel is deleted, notifications assigned to that channel will fail to display. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android * @param channelId The unique channel ID to delete. */ deleteChannel(channelId: string): Promise; /** * API used to delete a channel group by ID on supported Android devices. * * Channel groups can be deleted using this API by providing the channel ID. Channel information (including * the ID) can be retrieved from the [`getChannels`](/react-native/reference/getchannels) API. * * Deleting a group does not delete channels which are assigned to the group, they will instead be * unassigned the group and continue to function as expected. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android * @param channelGroupId The unique channel group ID to delete. */ deleteChannelGroup(channelGroupId: string): Promise; /** * API used to immediately display or update a notification on the users device. * * This API is used to display a notification on the users device. All * channels/categories should be created before triggering this method during the apps lifecycle. * * View the [Displaying a Notification](/react-native/displaying-a-notification) * documentation for more information. * * @param notification The [`Notification`](/react-native/reference/notification) interface used * to create a notification for both Android & iOS. */ displayNotification(notification: Notification): Promise; /** * API used to open the Android Alarm special access settings for the application. * * On Android >= 12 / API >= 31, the alarm special access settings screen is displayed, otherwise, * this is a no-op & instantly resolves. * * View the [Trigger](/react-native/android/triggers#android-12-limitations) documentation for more information. * * @platform android */ openAlarmPermissionSettings(): Promise; /** * API used to create a trigger notification. * * All channels/categories should be created before calling this method during the apps lifecycle. * * View the [Triggers](/react-native/triggers) documentation for more information. * * @param notification The [`Notification`](/react-native/reference/notification) interface used * to create a notification. * * @param trigger The [`Trigger`](/react-native/reference/trigger) interface used * to create a trigger. */ createTriggerNotification(notification: Notification, trigger: Trigger): Promise; /** * API used to return the ids of trigger notifications that are pending. * * View the [Triggers](/react-native/triggers) documentation for more information. */ getTriggerNotificationIds(): Promise; /** * API used to return the notifications that are displayed. */ getDisplayedNotifications(): Promise; /** * API used to return the trigger notifications that are pending. */ getTriggerNotifications(): Promise; /** * API used to return a channel on supported Android devices. * * This API is used to return a `NativeAndroidChannel`. Returns `null` if no channel could be matched to * the given ID. * * A "native channel" also includes additional properties about the channel at the time it's * retrieved from the device. View the [`NativeAndroidChannel`](/react-native/reference/nativeandroidchannel) * documentation for more information. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android * @param channelId The channel ID created with [`createChannel`](/react-native/reference/createchannel). If * a unknown channel ID is provided, `null` is returned. */ getChannel(channelId: string): Promise; /** * API used to check if a channel is created. * * On iOS, this will default to true * * @platform android */ isChannelCreated(channelId: string): Promise; /** * API used to check if a channel is blocked. * * On iOS, this will default to false * * @platform android */ isChannelBlocked(channelId: string): Promise; /** * API used to return all channels on supported Android devices. * * This API is used to return a `NativeAndroidChannel`. Returns an empty array if no channels * exist. * * A "native channel" also includes additional properties about the channel at the time it's * retrieved from the device. View the [`NativeAndroidChannel`](/react-native/reference/nativeandroidchannel) * documentation for more information. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android */ getChannels(): Promise; /** * API used to return a channel group on supported Android devices. * * This API is used to return an `NativeAndroidChannelGroup`. Returns `null` if no channel could be matched to * the given ID. * * A "native channel group" also includes additional properties about the channel group at the time it's * retrieved from the device. View the [`NativeAndroidChannelGroup`](/react-native/reference/nativeandroidchannelgroup) * documentation for more information. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android * @param channelGroupId The channel ID created with [`createChannelGroup`](/react-native/reference/createchannelgroup). If * a unknown channel group ID is provided, `null` is returned. */ getChannelGroup(channelGroupId: string): Promise; /** * API used to return all channel groups on supported Android devices. * * This API is used to return a `NativeAndroidChannelGroup`. Returns an empty array if no channel * groups exist. * * A "native channel group" also includes additional properties about the channel group at the time it's * retrieved from the device. View the [`NativeAndroidChannelGroup`](/react-native/reference/nativeandroidchannelgroup) * documentation for more information. * * View the [Channels & Groups](/react-native/android/channels) documentation for more information. * * @platform android */ getChannelGroups(): Promise; /** * API used to fetch the notification which causes the application to open. * * This API can be used to fetch which notification & press action has caused the application to * open. The call returns a `null` value when the application wasn't launched by a notification. * * Once the initial notification has been consumed by this API, it is removed and will no longer * be available. It will also be removed if the user relaunches the application. * * View the [App open events](/react-native/events#app-open-events) documentation for more * information and example usage. * * Deprecated for iOS in favour of `onForegroundEvent` - you can still use this method on iOS * but you will also receive a `onForegroundEvent` */ getInitialNotification(): Promise; /** * API used to handle events when the application is in a background state. * * Applications in a background state will use an event handler registered by this API method * to send events. The handler must return a Promise once complete and only a single event handler * can be registered for the application. * * View the [Background events](/react-native/events#background-events) documentation for more * information and example usage. * * To listen to foreground events, see the [`onForegroundEvent`](/react-native/reference/onforegroundevent) documentation. * * @param observer A Function which returns a Promise, called on a new event when the application * is in a background state. */ onBackgroundEvent(observer: (event: Event) => Promise): void; /** * API used to handle events when the application is in a foreground state. * * Applications in a foreground state will use an event handler registered by this API method * to send events. Multiple foreground observers can be registered throughout the applications * lifecycle. The method returns a function, used to unsubscribe from further events, * * View the [Foreground events](/react-native/events#foreground-events) documentation for more * information and example usage. * * To listen to background events, see the [`onBackgroundEvent`](/react-native/reference/onbackgroundevent) documentation. * * @param observer A Function which returns a Promise, called on a new event when the application * is in a foreground state. */ onForegroundEvent(observer: (event: Event) => void): () => void; /** * API used to open the Android System settings for the application. * * If the API version is >= 26: * - With no `channelId`, the notification settings screen is displayed. * - With a `channelId`, the notification settings screen for the specific channel is displayed. * * If the API version is < 26, the application settings screen is displayed. The `channelId` * is ignored. * * If an invalid `channelId` is provided (e.g. does not exist), the settings screen will redirect * back to your application. * * On iOS, this is a no-op & instantly resolves. * * @platform android * @param channelId The ID of the channel which will be opened. Can be ignored/omitted to display the * overall notification settings. */ openNotificationSettings(channelId?: string): Promise; /** * API used to register a foreground service on Android devices. * * This method is used to register a long running task which can be used with Foreground Service * notifications. * * Only a single foreground service can exist for the application, and calling this method more * than once will update the existing task runner. * * View the [Foreground Service](/react-native/android/foreground-service) documentation for * more information. * * @platform android * @param task The runner function which runs for the duration of the service's lifetime. */ registerForegroundService(task: ForegroundServiceTask): void; /** * Call this to stop the foreground service that is running * * @platform android * */ stopForegroundService(): Promise; /** * Pre-warms the foreground service notification path by eagerly loading critical * classes and warming the `INotificationManager` Binder proxy on a background thread. * * Most apps do **not** need this method — the library automatically performs warmup * at app startup via `InitProvider`. This API is an escape hatch for edge cases: * * - Apps where the library is lazy-loaded or code-split * - Apps that want to defer warmup to after the splash screen * - Low-end devices where the `InitProvider` warmup hasn't finished by the time * the first notification is displayed * * Safe to call multiple times (idempotent). On iOS this resolves immediately as a no-op. * * See the "Advanced / Troubleshooting" section in the README for more details. * * @platform android */ prewarmForegroundService(): Promise; /** * Request specific notification permissions for your application on the current device. * * Both iOS & Android return an `NotificationSettings` interface. To check whether overall * permission was granted, check the `authorizationStatus` property in the response: * * ```js * import notifee, { AuthorizationStatus } from 'react-native-notify-kit'; * * const settings = await notifee.requestPermission(...); * * if (settings.authorizationStatus === AuthorizationStatus.DENIED) { * console.log('User denied permissions request'); * } else if (settings.authorizationStatus === AuthorizationStatus.AUTHORIZED) { * console.log('User granted permissions request'); * } else if (settings.authorizationStatus === AuthorizationStatus.PROVISIONAL) { * console.log('User provisionally granted permissions request'); * } * ``` * * For iOS specific settings, use the `ios` properties to view which specific permissions were * authorized. * * On Android, `authorizationStatus` will return only either `AuthorizationStatus.DENIED` or `AuthorizationStatus.AUTHORIZED` * and all of the properties on the `ios` interface response return as `AUTHORIZED`. * * @param permissions */ requestPermission(permissions?: IOSNotificationPermissions): Promise; /** * Set the notification categories to be used on this Apple device. * * @platform ios * * @param categories */ setNotificationCategories(categories: IOSNotificationCategory[]): Promise; /** * Gets the currently set notification categories on this Apple device. * * Returns an empty array on Android. * *@platform ios */ getNotificationCategories(): Promise; /** * Get the current notification settings for this application on the current device. * On Android 13+ (API 33+), `authorizationStatus` returns `AuthorizationStatus.NOT_DETERMINED` before * `requestPermission()` is called, `AuthorizationStatus.DENIED` if denied, or `AuthorizationStatus.AUTHORIZED` * if granted. On Android < 13, returns only `DENIED` or `AUTHORIZED`. * All properties on the `IOSNotificationSettings` interface response return as `AUTHORIZED` on Android. */ getNotificationSettings(): Promise; /** * Get the current badge count value for this application on the current device. * * Returns `0` on Android. * * @platform ios */ getBadgeCount(): Promise; /** * Set the badge count value for this application on the current device. * * If set to zero, the badge count is removed from the device. The count must also * be a positive number. * * @platform ios * * @param count The number value to set as the badge count. */ setBadgeCount(count: number): Promise; /** * Increments the badge count for this application on the current device by a specified * value. * * Defaults to an increment of `1`. * * @platform ios * * @param incrementBy The value to increment the badge count by. */ incrementBadgeCount(incrementBy?: number): Promise; /** * Decrements the badge count for this application on the current device by a specified * value. * * Defaults to an decrement of `1`. * * @platform ios */ decrementBadgeCount(decrementBy?: number): Promise; /** * API used to configure iOS notification handling behavior. * * Use this to control whether Notify Kit should handle remote (push) notifications * on iOS. When `handleRemoteNotifications` is set to `false`, remote notifications * (e.g. from Firebase Cloud Messaging) will be forwarded to the original * notification delegate instead of being processed by Notify Kit. * * This allows libraries like React Native Firebase Messaging to receive tap events * via `onNotificationOpenedApp()` and `getInitialNotification()`. * * Defaults to `true` (Notify Kit handles all notifications) for backward compatibility. * * ```js * import notifee from 'react-native-notify-kit'; * * // Disable Notify Kit handling of remote notifications * await notifee.setNotificationConfig({ * ios: { handleRemoteNotifications: false }, * }); * ``` * * @platform ios */ setNotificationConfig(config: { ios?: IOSNotificationConfig }): Promise; /** * API used to open the Android System settings for the application. * * If the API version is >= 23, the battery optimization settings screen is displayed, otherwise, * this is a no-op & instantly resolves. * * View the [Background Restrictions](/react-native/android/behaviour#background-restrictions) documentation for more information. * * @platform android */ openBatteryOptimizationSettings(): Promise; /** * API used to check if battery optimization is enabled for your application. * * Supports API versions >= 23. * * View the [Background Restrictions](/react-native/android/behaviour#background-restrictions) documentation for more information. * * @platform android */ isBatteryOptimizationEnabled(): Promise; /** * API used to get best-effort information about the device and its power manager settings, including manufacturer, model, version and a known activity candidate. * * The returned `activity` is based on Notify Kit's manufacturer mapping and is not * prevalidated with `PackageManager`. A non-null value does not guarantee that * `openPowerManagerSettings()` can open that screen on the current device firmware. * * Notify Kit does not rely on Android 11+ package-visibility queries for this helper, * so consumer apps do not need to add `` to use it. * * If `activity` is `null`, `openPowerManagerSettings()` will be a no-op because * there is no known vendor-settings candidate. * * On iOS, an instance of `PowerManagerInfo` will be returned with `activity` set to `null`. * * View the [Background Restrictions](/react-native/android/background-restrictions) documentation for more information. * * ```js * import notifee from `react-native-notify-kit`; * * const powerManagerInfo = await notifee.getPowerManagerInfo(); * * if (powerManagerInfo.activity) { * // 1. ask the user to adjust their Power Manager settings * // ... * * // 2. open settings best-effort * await notifee.openPowerManagerSettings(); * } * ``` * * @platform android */ getPowerManagerInfo(): Promise; /** * API used to best-effort open known Android System power manager settings for the device. * * Call `getPowerManagerInfo()` first to decide whether to prompt the user. A * non-null `activity` means Notify Kit has a known vendor-settings candidate, not * that Android has confirmed the activity exists or is accessible. * * Notify Kit does not require consumer apps to add `` for this helper. If * Android rejects or cannot resolve a vendor settings intent, the method safely * falls back or no-ops instead of crashing. * * View the [Background Restrictions](/react-native/android/background-restrictions) documentation for more information. * * ```js * import notifee from `react-native-notify-kit`; * * const powerManagerInfo = await notifee.getPowerManagerInfo * * if (powerManagerInfo.activity) { * // 1. ask the user to adjust their Power Manager settings * // ... * * // 2. if yes, try to open settings * await notifee.openPowerManagerSettings(); * } * ``` * * @platform android */ openPowerManagerSettings(): Promise; /** * API used to hide the notification drawer, for example, * when the user presses one of the quick actions on the notification, you may wish to hide the drawer. * * Please use this functionality carefully as it could potentially be quite intrusive to the user. * * Requires the following permission to be added to your `AndroidManifest.xml`: * ```xml * * ``` * * ```js * import notifee from `react-native-notify-kit`; * * notifee.hideNotificationDrawer(); * ``` * * @platform android */ hideNotificationDrawer(): void; /** * Builds a notification from an FCM remote message without displaying it. * * The notification is returned before display validation, so it may not have * an ID and can be modified before being passed to {@link displayNotification}. * Returns `null` only when `notifee_options` is absent or invalid and * `fallbackBehavior` is configured as `'ignore'`. */ buildFcmNotification(remoteMessage: FcmRemoteMessage): Notification | null; /** * Processes an FCM remote message produced by the Notify Kit server SDK and * displays a Notify Kit notification according to the embedded `notifee_options`. * * Safe to call from both `setBackgroundMessageHandler` and `onMessage`. * * @returns The displayed notification ID, or `null` if the call was an * intentional no-op (iOS background, `fallbackBehavior: 'ignore'`, * `suppressForegroundBanner`). */ handleFcmMessage(remoteMessage: FcmRemoteMessage): Promise; /** * Configures defaults for {@link buildFcmNotification} and {@link handleFcmMessage}. * Call once at app startup, typically in `index.js` before `registerComponent`. * * Returns Promise for forward compatibility — a future version may persist * config across cold starts, which would be async. Currently resolves * synchronously. */ setFcmConfig(config: FcmConfig): Promise; } /** * Interface describing the static properties available on the default `react-native-notify-kit` export. * * ```js * import notifee from `react-native-notify-kit`; * * console.log(notifee.SDK_VERSION); * ``` */ export interface ModuleStatics { /** * Returns the current Notify Kit SDK version in use. */ SDK_VERSION: string; } export interface ModuleWithStatics extends Module, ModuleStatics {}