React Native · APIs and utilities
Notifications
Notification API.
Import
Notifications
moduleNotification API. Showing needs permission: Permissions.request("notifications") (Android 13+ and iOS).
| Name | Type | Description |
|---|---|---|
schedule | (request: NotificationRequest) => Promise<string> | Schedules a notification (shows it immediately without a trigger); returns its id. On Android scheduled ones survive a device reboot. |
present | (request: Omit<NotificationRequest, "trigger">) => Promise<string> | Shows immediately. |
cancel | (id: string) => Promise<void> | Cancels a scheduled notification (does not close a shown one: Notifications.dismiss). |
cancelAll | () => Promise<void> | Cancels all scheduled notifications. |
getScheduled | () => Promise<ScheduledNotification[]> | Scheduled notifications. |
dismiss | (id: string) => Promise<void> | Removes a notification from the notification center. |
dismissAll | () => Promise<void> | Removes all notifications from the notification center. |
getPresented | () => Promise<PresentedNotification[]> | The ones visible in the notification center. |
setBadge | (count: number) => Promise<void> | Badge on the app icon (iOS). On Android launchers compute the badge from the notifications themselves; the value is only stored. |
getBadge | () => Promise<number> | The badge count last set with setBadge. |
createChannel | (options: ChannelOptions) => Promise<void> | Creates/updates an Android channel (afterwards only the user can change its importance). |
deleteChannel | (id: string) => Promise<void> | Deletes an Android channel and the user's settings for it. |
getChannels | () => Promise<NotificationChannel[]> | The app's Android channels (empty on iOS). |
setCategories | (categories: readonly NotificationCategory[]) => Promise<void> | Defines action button sets (replacing the previous ones). |
setForegroundPresentation | (options: ForegroundPresentation) => void | How a notification arriving in the foreground is presented (default: all on). |
getInitialResponse | () => NotificationResponse | null | The tap that opened the app (or the last tap that arrived with no listener). Every call returns the same value within the same JS session. |
addReceivedListener | (listener: (notification: NotificationContent) => void) => () => void | A notification arriving in the foreground. |
addResponseListener | (listener: (response: NotificationResponse) => void) => () => void | A tap on a notification or an action button. |
canScheduleExactAlarms | () => boolean | Android: whether exact alarms can be used (ui.config notifications.android.exactAlarms and user permission). Always true on iOS. |
openSettings | (options?: { channel?: string; page?: "exactAlarms"; }) => Promise<void> | Opens notification settings. Android: with channel, that channel's page; with "exactAlarms", the exact alarm permission page. |
isPushAvailable | () => boolean | Whether remote notifications are enabled in the build (ui.config notifications). |
getPushToken | () => Promise<PushToken> | Remote notification token. On iOS request notification permission first. Error codes: E_PUSH_DISABLED (off in settings), E_PUSH (registration failed; expected on a simulator and in unsigned builds). |
deletePushToken | () => Promise<void> | Deletes the token (sign out); the next request gives a new token. |
setBackgroundHandler | (handler: NotificationBackgroundHandler | null) => void | Handler for actions that do not open the app (foreground: false): marking as read, sending an inline reply… It also runs while the app is closed (an Android headless JS task, an iOS background launch). Call it outside components, in the app's root file (index.js), so it is defined on a background launch too. Without a handler these taps arrive at Notifications.addResponseListener when the app opens. |
addTokenListener | (listener: (token: PushToken) => void) => () => void | The token changed (iOS renews it on every launch; Android when FCM refreshes it). |
NOTIFICATION_ACTION_TASK
constantKey of the headless JS task for background actions on the native side (Android).
normalizeTrigger
functionConverts a trigger to the native format.
useNotificationResponse
functionListens to taps; the tap that opened the app arrives once too. Use it in the root component for navigation.
Examples
useNotificationReceived
functionListens to notifications arriving in the foreground.
usePushToken
functionRemote notification token; obtained once permission is granted (enabled) and updated when it changes.
NotificationData
typeNotification data: JSON values.
When to show it:
{ date }: a specific moment (once).{ seconds, repeats? }: this long from now; withrepeatseverysecondsseconds (at least 60 for repeating on iOS).{ hour, minute, weekday? }: every day (or that day of the week) at that time.weekday1 = Sunday … 7 = Saturday. Once withrepeats: false.
| Name | Type | Default | Description |
|---|---|---|---|
date | Date | number | Moment to show it (a Date or ms, epoch).({ /** Moment to show it (a `Date` or ms, epoch). */ date: Date | number; }) | |
seconds | number | Delay in seconds.({ /** Delay in seconds. */ seconds: number; /** Repeat every `seconds` seconds. @defaultValue `false` */ repeats?: boolean; }) | |
repeats? | boolean | false | Repeat every seconds seconds.({ /** Delay in seconds. */ seconds: number; /** Repeat every `seconds` seconds. @defaultValue `false` */ repeats?: boolean; } | { /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday; every day if omitted. */ weekday?: number; /** Repeat every day/week. @defaultValue `true` */ repeats?: boolean; }) |
hour | number | Hour (0–23).({ /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday; every day if omitted. */ weekday?: number; /** Repeat every day/week. @defaultValue `true` */ repeats?: boolean; }) | |
minute | number | Minute (0–59).({ /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday; every day if omitted. */ weekday?: number; /** Repeat every day/week. @defaultValue `true` */ repeats?: boolean; }) | |
weekday? | number | Day of the week: 1 = Sunday … 7 = Saturday; every day if omitted.({ /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday; every day if omitted. */ weekday?: number; /** Repeat every day/week. @defaultValue `true` */ repeats?: boolean; }) |
NotificationRequest
interfaceA notification to show.
| Name | Type | Default | Description |
|---|---|---|---|
id? | string | Id; rescheduling with the same id replaces the previous one. Generated if not given. | |
title? | string | Title. | |
body? | string | Body text. | |
subtitle? | string | iOS subtitle; on Android a short text next to the title. | |
data? | NotificationData | Data returned when tapped. | |
trigger? | NotificationTrigger | Trigger; shown immediately if not given. | |
channel? | string | "default" | Android channel. |
category? | string | Category: action buttons (Notifications.setCategories). | |
group? | string | Grouping key (iOS threadIdentifier, Android group). | |
badge? | number | Badge count (on the iOS app icon; the notification's number on Android). | |
sound? | boolean | string | true | Sound: false silent, a string for a custom sound file (in the iOS app bundle; on Android the sound is bound to the channel, ChannelOptions.sound). |
color? | string | Android: accent color (#rrggbb); the one in ui.config if omitted. | |
sticky? | boolean | Android: cannot be dismissed by swiping (for ongoing work). |
NotificationContent
interfaceA received/shown notification.
| Name | Type | Description |
|---|---|---|
id | string | Notification id. |
title | string | null | Title. |
body | string | null | Body text. |
subtitle? | string | null | iOS subtitle; on Android the short text next to the title. |
data | NotificationData | Data given when scheduling. |
channel? | string | Android channel. |
category? | string | Category (action buttons). |
group? | string | Grouping key. |
badge? | number | Badge count. |
remote? | boolean | Whether it is a remote notification (push). |
ScheduledNotification
interfaceA scheduled notification.
| Name | Type | Description |
|---|---|---|
trigger | NormalizedTrigger | null | Trigger; null if unknown. |
nextDate | number | null | Next presentation (ms, epoch); null if unknown. |
id | string | Notification id. |
title | string | null | Title. |
body | string | null | Body text. |
subtitle? | string | null | iOS subtitle; on Android the short text next to the title. |
data | NotificationData | Data given when scheduling. |
channel? | string | Android channel. |
category? | string | Category (action buttons). |
group? | string | Grouping key. |
badge? | number | Badge count. |
remote? | boolean | Whether it is a remote notification (push). |
PresentedNotification
interfaceA notification in the notification center.
| Name | Type | Description |
|---|---|---|
date | number | When it was shown (ms, epoch). |
id | string | Notification id. |
title | string | null | Title. |
body | string | null | Body text. |
subtitle? | string | null | iOS subtitle; on Android the short text next to the title. |
data | NotificationData | Data given when scheduling. |
channel? | string | Android channel. |
category? | string | Category (action buttons). |
group? | string | Grouping key. |
badge? | number | Badge count. |
remote? | boolean | Whether it is a remote notification (push). |
NotificationResponse
interfaceA tap.
| Name | Type | Description |
|---|---|---|
notification | NotificationContent | The notification that was tapped. |
actionId | string | "default" (the notification was tapped), "dismiss" (iOS, dismissed) or the action's id. |
userText? | string | Text typed in an action with text input (input). |
Trigger sent to the native side.
| Name | Type | Description |
|---|---|---|
type | "date" | "interval" | "calendar" | Trigger kind. |
date | number | Moment (ms, epoch).({ /** Trigger kind. */ type: "date"; /** Moment (ms, epoch). */ date: number; }) |
seconds | number | Delay in seconds.({ /** Trigger kind. */ type: "interval"; /** Delay in seconds. */ seconds: number; /** Whether it repeats. */ repeats: boolean; }) |
repeats | boolean | Whether it repeats.({ /** Trigger kind. */ type: "interval"; /** Delay in seconds. */ seconds: number; /** Whether it repeats. */ repeats: boolean; } | { /** Trigger kind. */ type: "calendar"; /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday. */ weekday?: number; /** Whether it repeats. */ repeats: boolean; }) |
hour | number | Hour (0–23).({ /** Trigger kind. */ type: "calendar"; /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday. */ weekday?: number; /** Whether it repeats. */ repeats: boolean; }) |
minute | number | Minute (0–59).({ /** Trigger kind. */ type: "calendar"; /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday. */ weekday?: number; /** Whether it repeats. */ repeats: boolean; }) |
weekday? | number | Day of the week: 1 = Sunday … 7 = Saturday.({ /** Trigger kind. */ type: "calendar"; /** Hour (0–23). */ hour: number; /** Minute (0–59). */ minute: number; /** Day of the week: 1 = Sunday … 7 = Saturday. */ weekday?: number; /** Whether it repeats. */ repeats: boolean; }) |
NotificationAction
interfaceAn action button.
| Name | Type | Default | Description |
|---|---|---|---|
id | string | Action id; arrives as NotificationResponse.actionId. | |
title | string | Button text. | |
destructive? | boolean | Red (iOS). | |
foreground? | boolean | true | Opens the app. With false the JS Notifications.setBackgroundHandler handler runs in the background without opening the app (even while it is closed): for actions like "Mark as read", "Reply". |
authenticationRequired? | boolean | iOS: runs only when unlocked. | |
input? | { /** iOS: text of the send button. */ buttonTitle?: string; /** Hint in the empty field. */ placeholder?: string; /** Android: smart replies suggested by the system. @defaultValue `false` */ suggestions?: boolean; } | Text input (quick reply): typed inside the notification on both platforms; the text arrives in NotificationResponse.userText. | |
dismiss? | boolean | true` (`false` with text input) | Android, background action: close the notification when pressed. For an action with text input the default is false: the notification stays (in the handler you can update it with Notifications.present using the same id, or close it with Notifications.dismiss). iOS always closes the notification. |
NotificationCategory
interfaceA set of action buttons; chosen on a notification with category.
| Name | Type | Description |
|---|---|---|
id | string | Category id; given as category on a notification. |
actions | readonly NotificationAction[] | Action buttons, in order. |
Android channel importance.
ChannelOptions
interfaceAndroid notification channel (Android 8+; ignored on iOS).
| Name | Type | Default | Description |
|---|---|---|---|
id | string | Channel id; given as channel on a notification. | |
name | string | Name shown in settings. | |
description? | string | Description shown in settings. | |
importance? | ChannelImportance | "high" | |
sound? | boolean | string | false silent; a string is the name of a sound file under res/raw. | |
vibration? | boolean | Vibrates. | |
lights? | boolean | Blinks the notification light. | |
showBadge? | boolean | Shows a badge on the app icon. |
NotificationChannel
interfaceChannel info.
| Name | Type | Description |
|---|---|---|
id | string | Channel id. |
name | string | null | Name shown in settings. |
description | string | null | Description shown in settings. |
importance | ChannelImportance | Importance. |
showBadge | boolean | Shows a badge on the app icon. |
vibration | boolean | Vibrates. |
sound | boolean | Plays a sound. |
ForegroundPresentation
interfacePresentation of a notification arriving while the app is in the foreground. All default to true.
| Name | Type | Description |
|---|---|---|
banner? | boolean | Show it on top of the screen. |
list? | boolean | Add it to the notification center. |
sound? | boolean | Play the sound. |
badge? | boolean | Update the badge. |
PushToken
interfaceRemote notification token: APNs on iOS, FCM on Android. Send this to your server.
| Name | Type | Description |
|---|---|---|
type | "apns" | "fcm" | Token kind. |
token | string | Token value. |
Background action handler; when the returned Promise settles the system may suspend the app again (finish within ~25 s on iOS, 30 s on Android).