diff --git a/docs/general-events.md b/docs/general-events.md index f6154e0..5f765b0 100755 --- a/docs/general-events.md +++ b/docs/general-events.md @@ -13,12 +13,12 @@ Notifications.events().registerRemoteNotificationsRegistered((event: Registered) }); ``` -## registerNotificationReceived() +## registerNotificationReceivedForeground() Fired when a remote notification is received in foreground state. The handler will be invoked with an instance of [Notification](notification-object). Should call completion function on iOS, will be ignored on Android. ```js -Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => { +Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => { console.log(JSON.stringify(notification.data)); // Calling completion on iOS with `alert: true` will present the native iOS inApp notification. @@ -26,6 +26,21 @@ Notifications.events().registerNotificationReceived((notification: Notification, }); ``` +## registerNotificationReceivedBackground() +Fired when a remote notification is received in background state. The handler will be invoked with an instance of [Notification](notification-object). +Should call completion function on iOS, will be ignored on Android. + +```js +Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => { + console.log(JSON.stringify(notification.data)); + + // Calling completion on iOS with `alert: true` will present the native iOS inApp notification. + completion({alert: true, sound: true, badge: false}); +}); +``` + +To receive background notifications on iOS follow [this guide](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app) + ## registerNotificationOpened() Fired when a remote notification is opened from dead or background state. The handler will be invoked with an instance of [Notification](notification-object). Should call completion function on iOS, will be ignored on Android. diff --git a/docs/getting-started.md b/docs/getting-started.md index 72c9671..bae6594 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -69,7 +69,7 @@ class MyComponent extends Component { constructor() { Notifications.registerRemoteNotifications(); - Notifications.events().registerNotificationReceived((notification: Notification, completion) => { + Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => { console.log(`Notification received in foreground: ${notification.title} : ${notification.body}`); completion({alert: false, sound: false, badge: false}); }); diff --git a/docs/notification-object.md b/docs/notification-object.md index 309dbbc..3664df3 100755 --- a/docs/notification-object.md +++ b/docs/notification-object.md @@ -17,7 +17,7 @@ Contains the payload data. Example: ```js -Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => { +Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => { // Prints the notification payload console.log(JSON.stringify(notification.payload)); diff --git a/docs/notifications-events.md b/docs/notifications-events.md index d7d59db..7df70dd 100644 --- a/docs/notifications-events.md +++ b/docs/notifications-events.md @@ -6,7 +6,7 @@ sidebar_label: Events When a push notification is received by the device, the application can be in one of the following states: -1. **Forground:** When the app is running and is used by the user right now; in this case, a `notificationReceived` event will be fired, do not forget to invoke `completion()` callback. +1. **Forground:** When the app is running and is used by the user right now; in this case, a `notificationReceivedForeground` event will be fired, do not forget to invoke `completion()` callback. Finally, when a notification is _opened_ by the device user (i.e. tapped-on), a `notificationOpened` event is fired, here as well you need to remember invoking `completion()` callback. @@ -14,7 +14,7 @@ Example: ```jsx constructor() { - Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => { + Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => { console.log("Notification Received - Foreground", notification.data); // Calling completion on iOS with `alert: true` will present the native iOS inApp notification. diff --git a/example/index.js b/example/index.js index 1b3e0c2..42a4efc 100644 --- a/example/index.js +++ b/example/index.js @@ -21,7 +21,7 @@ class NotificationsExampleApp extends Component { } registerNotificationEvents() { - Notifications.events().registerNotificationReceived((notification, completion) => { + Notifications.events().registerNotificationReceivedForeground((notification, completion) => { this.setState({ notifications: [...this.state.notifications, notification] });