registerPushNotificationHandlers

This function sets up the push notification handlers. It is meant to be called in the app's first file: index.js or index.tsx. This is critical to ensuring that notifications are received and handled properly especially when the app is stopped.

DO NOT CALL THIS FUNCTION INSIDE ANY COMPONENT
1registerPushNotificationHandlers(
2 androidSettings?: AndroidSettings,
3 iosSettings?: IOSSettings
4): Promise<NotificationHandler>

Parameters

NameTypeDescription
androidSettingsAndroidSettingsAn object describing the Android Notification Channel to be created. Without a channel, notifications will not work.
iosSettingsIOSSettingsAn object indicating the different iOS push notification settings.

Returns

Promise<NotificationHandler>

Example

1// Inside your app's index.tsx
2import { AppRegistry } from 'react-native';
3import { registerPushNotificationHandlers } from '@talkjs/react-native';
4
5import App from './src/App';
6import { name as appName } from './app.json';
7
8registerPushNotificationHandlers(
9 {
10 channelId: 'com.example.reactnativetalkjs.messages',
11 channelName: 'Messages',
12 });
13
14AppRegistry.registerComponent(appName, () => App);

Type Definitions

AndroidSettings

This object describes the properties of the Notification Channel on Android.

Properties

FieldTypeDescription
channelId RequiredstringThe unique id of the channel.
channelName RequiredstringThe user visible name of the channel. The recommended maximum length is 40 characters; the value may be truncated if it is too long.
channelDescriptionstringThis is the description that the user sees in the system settings. The recommended maximum length is 300 characters; the value may be truncated if it is too long. Default: undefined
badgebooleanSets whether badges are enabled for the channel. Defaults to true.

This setting cannot be overridden once the channel is created.
lightsbooleanSets whether notifications posted to this channel should display notification lights, on devices that support that feature. Defaults to true.

This setting cannot be overridden once the channel is created.
lightsColorstringIf lights are enabled (via lights), sets/overrides the light color for notifications posted to this channel.

This setting cannot be overridden once the channel is created.
bypassDndbooleanSets whether or not notifications posted to this channel can interrupt the user in 'Do Not Disturb' mode. Defaults to false.

This setting cannot be overridden once the channel is created.
importanceImportanceAn integer determining the importance of the channel. This controls how interruptive notifications posted to this channel are. Read more.. Default: Importance.HIGH
visibilityAndroidVisibilitySets whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form.
playSoundbooleanDetermines whether the notification sound should be played. Default: true.
soundNamestringSound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the my_sound audio file in [project_root]/android/app/src/main/res/raw directory and play it.
Default: 'default'
vibratebooleanCreates the default vibration pattern if true. Default: true
vibrationPatternnumber[]Sets/overrides the vibration pattern for notifications posted to this channel. The pattern in milliseconds. Must be an even amount of numbers.

IOSSettings

This object configures the appropriate iOS push notification service.

Properties

FieldTypeDescription
useFirebasebooleanWhether your app is using Firebase push notifications on iOS.

Importance

This is an enum that represents the various notification importance levels available on Android.

Enum Members

NameValueDescription
HIGH4Makes a sound, shows everywhere and peeks. May use full screen intents
DEFAULT3Makes a sound, shows everywhere but does not visually intrude.
LOW2No sound, shows in the shade and potentially in the status bar.
MIN1No sound and only shows in the shade.
NONE0A notification with no importance: does not show in the shade.

Visibility

This is an enum that determines whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form.

Enum Members

NameValueDescription
PRIVATE0Show the notification on all lockscreens, but conceal sensitive or private information on secure lockscreens.
PUBLIC1Show this notification in its entirety on all lockscreens.
SECRET-1Do not reveal any part of this notification on a secure lockscreen.