Commit 6230fdb9 authored by yogevbd's avatar yogevbd

Updated docs

parent c97e559a
...@@ -91,27 +91,12 @@ After [preparing your app to receive VoIP push notifications](https://developer. ...@@ -91,27 +91,12 @@ After [preparing your app to receive VoIP push notifications](https://developer.
#import <PushKit/PushKit.h> #import <PushKit/PushKit.h>
``` ```
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()`: In your ReactNative code, add event handler for `pushKitRegistered` event and call to `registerPushKit()`:
```javascript ```javascript
constructor() { constructor() {
NotificationsIOS.addEventListener('pushKitRegistered', this.onPushKitRegistered.bind(this)); NotificationsIOS.addEventListener('pushKitRegistered', this.onPushKitRegistered.bind(this));
NotificationsIOS.registerPushKit(); NotificationsIOS.registerPushKit();
} }
onPushKitRegistered(deviceToken) { onPushKitRegistered(deviceToken) {
......
...@@ -5,39 +5,35 @@ ...@@ -5,39 +5,35 @@
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 `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: Example:
```javascript ```javascript
constructor() { constructor() {
this._boundOnNotificationReceivedForeground = this.onNotificationReceivedForeground.bind(this); this._boundOnNotificationReceivedForeground = this.onNotificationReceivedForeground.bind(this);
this._boundOnNotificationReceivedBackground = this.onNotificationReceivedBackground.bind(this);
this._boundOnNotificationOpened = this.onNotificationOpened.bind(this); this._boundOnNotificationOpened = this.onNotificationOpened.bind(this);
NotificationsIOS.addEventListener('notificationReceivedForeground', this._boundOnNotificationReceivedForeground); NotificationsIOS.addEventListener('notificationReceivedForeground', this._boundOnNotificationReceivedForeground);
NotificationsIOS.addEventListener('notificationReceivedBackground', this._boundOnNotificationReceivedBackground);
NotificationsIOS.addEventListener('notificationOpened', this._boundOnNotificationOpened); NotificationsIOS.addEventListener('notificationOpened', this._boundOnNotificationOpened);
} }
onNotificationReceivedForeground(notification) { onNotificationReceivedForeground(notification, completion) {
completion({alert: true, sound: false, badge: false});
console.log("Notification Received - Foreground", notification); console.log("Notification Received - Foreground", notification);
} }
onNotificationReceivedBackground(notification) { onNotificationOpened(notification, completion, action) {
console.log("Notification Received - Background", notification);
}
onNotificationOpened(notification) {
console.log("Notification opened by device user", notification); 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() { componentWillUnmount() {
// Don't forget to remove the event listeners to prevent memory leaks! // Don't forget to remove the event listeners to prevent memory leaks!
NotificationsIOS.removeEventListener('notificationReceivedForeground', this._boundOnNotificationReceivedForeground); NotificationsIOS.removeEventListener('notificationReceivedForeground', this._boundOnNotificationReceivedForeground);
NotificationsIOS.removeEventListener('notificationReceivedBackground', this._boundOnNotificationReceivedBackground);
NotificationsIOS.removeEventListener('notificationOpened', this._boundOnNotificationOpened); NotificationsIOS.removeEventListener('notificationOpened', this._boundOnNotificationOpened);
} }
``` ```
...@@ -53,12 +49,6 @@ When you receive a push notification, you'll get an instance of `IOSNotification ...@@ -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. - **`getData()`**- returns the data payload (additional info) of the notification.
- **`getType()`**- returns `managed` for managed notifications, otherwise returns `regular`. - **`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.
## <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/APK_format_icon.png/768px-APK_format_icon.png" width=30/> Android ## <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/APK_format_icon.png/768px-APK_format_icon.png" width=30/> Android
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment