registerPushNotificationHandlers

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

DO NOT CALL THIS FUNCTION INSIDE ANY COMPONENT
registerPushNotificationHandlers(
androidChannel?: ChannelObject,
iosPermissions?: IOSPermissions
): Promise<void>

Parameters

NameTypeDescription
androidChannelAndroidChannelAn Object describing the Android Notification Channel to be created. Without a channel, notifications will not work.
iosPermissionsIOSPermissionsAn Object indicating the different iOS permissions that can be requested.

Returns

Promise<void>

Example

typescript
// Inside your app's index.tsx
import { AppRegistry } from 'react-native';
import { registerPushNotificationHandlers } from '@talkjs/react-native';
import App from './src/App';
import { name as appName } from './app.json';
registerPushNotificationHandlers(
{
channelId: 'com.example.reactnativetalkjs.messages',
channelName: 'Messages',
},
{
sound: true,
badge: true,
alert: true,
});
AppRegistry.registerComponent(appName, () => App);

Type Definitions

AndroidChannel

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.

IOSPermissions

This object indicates the various push notification related permissions that can be requested.

Properties

FieldTypeDescription
alertbooleanThe ability to display notification alerts.
badgebooleanThe ability to update the app's badge.
soundbooleanThe ability to play notification sounds.
criticalbooleanThe ability to play sounds for critical alerts which bypass Do Not Disturb or Silent modes.

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.