From 6230fdb908ca8386741a04978c8c4bdf40a061f6 Mon Sep 17 00:00:00 2001 From: yogevbd Date: Tue, 9 Jul 2019 14:55:18 +0300 Subject: [PATCH] Updated docs --- docs/advancedIos.md | 17 +---------------- docs/notificationsEvents.md | 24 +++++++----------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/docs/advancedIos.md b/docs/advancedIos.md index 584a28e..e58fc16 100644 --- a/docs/advancedIos.md +++ b/docs/advancedIos.md @@ -91,27 +91,12 @@ After [preparing your app to receive VoIP push notifications](https://developer. #import ``` -And the following methods: - -```objective-c -// PushKit API Support -- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type -{ - [RNNotifications didUpdatePushCredentials:credentials forType:type]; -} - -- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type -{ - [RNNotifications didReceiveRemoteNotification:payload.dictionaryPayload]; -} -``` - In your ReactNative code, add event handler for `pushKitRegistered` event and call to `registerPushKit()`: ```javascript constructor() { NotificationsIOS.addEventListener('pushKitRegistered', this.onPushKitRegistered.bind(this)); - NotificationsIOS.registerPushKit(); + NotificationsIOS.registerPushKit(); } onPushKitRegistered(deviceToken) { diff --git a/docs/notificationsEvents.md b/docs/notificationsEvents.md index 124e76c..21cdef3 100644 --- a/docs/notificationsEvents.md +++ b/docs/notificationsEvents.md @@ -5,39 +5,35 @@ 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. +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. +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. Example: ```javascript constructor() { this._boundOnNotificationReceivedForeground = this.onNotificationReceivedForeground.bind(this); - this._boundOnNotificationReceivedBackground = this.onNotificationReceivedBackground.bind(this); this._boundOnNotificationOpened = this.onNotificationOpened.bind(this); NotificationsIOS.addEventListener('notificationReceivedForeground', this._boundOnNotificationReceivedForeground); - NotificationsIOS.addEventListener('notificationReceivedBackground', this._boundOnNotificationReceivedBackground); NotificationsIOS.addEventListener('notificationOpened', this._boundOnNotificationOpened); } -onNotificationReceivedForeground(notification) { +onNotificationReceivedForeground(notification, completion) { + completion({alert: true, sound: false, badge: false}); console.log("Notification Received - Foreground", notification); } -onNotificationReceivedBackground(notification) { - console.log("Notification Received - Background", notification); -} - -onNotificationOpened(notification) { +onNotificationOpened(notification, completion, action) { console.log("Notification opened by device user", notification); + console.log(`Notification opened with an action identifier: ${action.identifier} and response text: ${action.text}`, notification); + completion(); } componentWillUnmount() { // Don't forget to remove the event listeners to prevent memory leaks! NotificationsIOS.removeEventListener('notificationReceivedForeground', this._boundOnNotificationReceivedForeground); - NotificationsIOS.removeEventListener('notificationReceivedBackground', this._boundOnNotificationReceivedBackground); NotificationsIOS.removeEventListener('notificationOpened', this._boundOnNotificationOpened); } ``` @@ -53,12 +49,6 @@ When you receive a push notification, you'll get an instance of `IOSNotification - **`getData()`**- returns the data payload (additional info) of the notification. - **`getType()`**- returns `managed` for managed notifications, otherwise returns `regular`. -### Background Queue (Important - please read!) - -When a push notification is opened but the app is not running, the application will be in a **cold launch** state, until the JS engine is up and ready to handle the notification. -The application will collect the events (notifications, actions, etc.) that happend during the cold launch for you. - -When your app is ready (most of the time it's after the call to `requestPermissions()`), just call to `NotificationsIOS.consumeBackgroundQueue();` in order to consume the background queue. For more info see `index.ios.js` in the example app. ## Android -- 2.26.2