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.
1registerPushNotificationHandlers(2 androidSettings?: AndroidSettings,3 iosSettings?: IOSSettings4): Promise<NotificationHandler>
Name | Type | Description |
---|---|---|
androidSettings | AndroidSettings | An object describing the Android Notification Channel to be created. Without a channel, notifications will not work. |
iosSettings | IOSSettings | An object indicating the different iOS push notification settings. |
1// Inside your app's index.tsx2import { AppRegistry } from 'react-native';3import { registerPushNotificationHandlers } from '@talkjs/react-native';45import App from './src/App';6import { name as appName } from './app.json';78registerPushNotificationHandlers(9 {10 channelId: 'com.example.reactnativetalkjs.messages',11 channelName: 'Messages',12 });1314AppRegistry.registerComponent(appName, () => App);
This object describes the properties of the Notification Channel on Android.
Field | Type | Description |
---|---|---|
channelId Required | string | The unique id of the channel. |
channelName Required | string | The user visible name of the channel. The recommended maximum length is 40 characters; the value may be truncated if it is too long. |
channelDescription | string | This 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 |
badge | boolean | Sets whether badges are enabled for the channel. Defaults to true . This setting cannot be overridden once the channel is created. |
lights | boolean | Sets 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. |
lightsColor | string | If 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. |
bypassDnd | boolean | Sets 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. |
importance | Importance | An integer determining the importance of the channel. This controls how interruptive notifications posted to this channel are. Read more.. Default: Importance.HIGH |
visibility | AndroidVisibility | Sets whether notifications posted to this channel appear on the lockscreen or not, and if so, whether they appear in a redacted form. |
playSound | boolean | Determines whether the notification sound should be played. Default: true . |
soundName | string | Sound 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' |
vibrate | boolean | Creates the default vibration pattern if true. Default: true |
vibrationPattern | number[] | Sets/overrides the vibration pattern for notifications posted to this channel. The pattern in milliseconds. Must be an even amount of numbers. |
This object configures the appropriate iOS push notification service.
Field | Type | Description |
---|---|---|
useFirebase | boolean | Whether your app is using Firebase push notifications on iOS. |
This is an enum that represents the various notification importance levels available on Android.
Name | Value | Description |
---|---|---|
HIGH | 4 | Makes a sound, shows everywhere and peeks. May use full screen intents |
DEFAULT | 3 | Makes a sound, shows everywhere but does not visually intrude. |
LOW | 2 | No sound, shows in the shade and potentially in the status bar. |
MIN | 1 | No sound and only shows in the shade. |
NONE | 0 | A notification with no importance: does not show in the shade. |
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.
Name | Value | Description |
---|---|---|
PRIVATE | 0 | Show the notification on all lockscreens, but conceal sensitive or private information on secure lockscreens. |
PUBLIC | 1 | Show this notification in its entirety on all lockscreens. |
SECRET | -1 | Do not reveal any part of this notification on a secure lockscreen. |