This commit is contained in:
yogevbd
2020-01-17 21:29:40 +02:00
parent 4e6f4d82c8
commit 6f20beb496
2 changed files with 20 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ 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));
console.log(JSON.stringify(notification.payload));
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({alert: true, sound: true, badge: false});
@@ -31,8 +31,8 @@ Fired when a remote notification is received in background state. The handler wi
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));
Notifications.events().registerNotificationReceivedBackground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
console.log(JSON.stringify(notification.payload));
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({alert: true, sound: true, badge: false});
@@ -47,7 +47,7 @@ Should call completion function on iOS, will be ignored on Android.
```js
Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void) => {
console.log(JSON.stringify(notification.data));
console.log(JSON.stringify(notification.payload));
completion();
});
```

View File

@@ -7,6 +7,8 @@ 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 `notificationReceivedForeground` event will be fired, do not forget to invoke `completion()` callback.
2. **Background:** `notificationReceivedBackground` event will be fired, do not forget to invoke `completion()` callback.
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)
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.
@@ -15,16 +17,23 @@ Example:
```jsx
constructor() {
Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
console.log("Notification Received - Foreground", notification.data);
console.log("Notification Received - Foreground", notification.payload);
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({alert: true, sound: true, badge: false});
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({alert: true, sound: true, badge: false});
});
Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void, action: NotificationActionResponse) => {
console.log("Notification opened by device user", notification.data);
console.log(`Notification opened with an action identifier: ${action.identifier} and response text: ${action.text}`);
completion();
console.log("Notification opened by device user", notification.payload);
console.log(`Notification opened with an action identifier: ${action.identifier} and response text: ${action.text}`);
completion();
});
Notifications.events().registerNotificationReceivedBackground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
console.log("Notification Received - Background", notification.payload);
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({alert: true, sound: true, badge: false});
});
}
```
@@ -42,7 +51,7 @@ import {Notifications} from 'react-native-notifications';
Notifications.getInitialNotification()
.then((notification) => {
console.log("Initial notification was:", (notification ? notification.data : 'N/A'));
console.log("Initial notification was:", (notification ? notification.payload : 'N/A'));
})
.catch((err) => console.error("getInitialNotifiation() failed", err));