mirror of
https://github.com/zhigang1992/react-native-notifications.git
synced 2026-04-30 13:21:51 +08:00
Update docs
This commit is contained in:
@@ -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).
|
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.
|
Should call completion function on iOS, will be ignored on Android.
|
||||||
|
|
||||||
```js
|
```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));
|
console.log(JSON.stringify(notification.data));
|
||||||
|
|
||||||
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
|
// 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()
|
## 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).
|
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.
|
Should call completion function on iOS, will be ignored on Android.
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class MyComponent extends Component {
|
|||||||
constructor() {
|
constructor() {
|
||||||
Notifications.registerRemoteNotifications();
|
Notifications.registerRemoteNotifications();
|
||||||
|
|
||||||
Notifications.events().registerNotificationReceived((notification: Notification, completion) => {
|
Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => {
|
||||||
console.log(`Notification received in foreground: ${notification.title} : ${notification.body}`);
|
console.log(`Notification received in foreground: ${notification.title} : ${notification.body}`);
|
||||||
completion({alert: false, sound: false, badge: false});
|
completion({alert: false, sound: false, badge: false});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Contains the payload data.
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
```js
|
```js
|
||||||
Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => {
|
Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
|
||||||
// Prints the notification payload
|
// Prints the notification payload
|
||||||
console.log(JSON.stringify(notification.payload));
|
console.log(JSON.stringify(notification.payload));
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
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.
|
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
|
```jsx
|
||||||
constructor() {
|
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);
|
console.log("Notification Received - Foreground", notification.data);
|
||||||
|
|
||||||
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
|
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class NotificationsExampleApp extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerNotificationEvents() {
|
registerNotificationEvents() {
|
||||||
Notifications.events().registerNotificationReceived((notification, completion) => {
|
Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
notifications: [...this.state.notifications, notification]
|
notifications: [...this.state.notifications, notification]
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user