|
1 |
| -# React Native Push Notifications |
| 1 | + # React Native Push Notifications |
2 | 2 |
|
3 | 3 | [](http://badge.fury.io/js/react-native-push-notification)
|
4 | 4 | [](http://badge.fury.io/js/react-native-push-notification)
|
@@ -56,9 +56,26 @@ Having a problem? Read the [troubleshooting](./trouble-shooting.md) guide before
|
56 | 56 |
|
57 | 57 | ## iOS manual Installation
|
58 | 58 |
|
59 |
| -The component uses PushNotificationIOS for the iOS part. |
| 59 | +The component uses PushNotificationIOS for the iOS part. You should follow their [installation instructions](https://github.com/react-native-community/react-native-push-notification-ios). |
60 | 60 |
|
61 |
| -[Please see: PushNotificationIOS](https://github.com/react-native-community/react-native-push-notification-ios) |
| 61 | +When done, modify the following method in the file `AppDelegate.m`: |
| 62 | +```objective-c |
| 63 | +// Called when a notification is delivered to a foreground app. |
| 64 | +-(void)userNotificationCenter:(UNUserNotificationCenter *)center |
| 65 | + willPresentNotification:(UNNotification *)notification |
| 66 | + withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler |
| 67 | +{ |
| 68 | + // Still call the JS onNotification handler so it can display the new message right away |
| 69 | + NSDictionary *userInfo = notification.request.content.userInfo; |
| 70 | + [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo |
| 71 | + fetchCompletionHandler:^void (UIBackgroundFetchResult result){}]; |
| 72 | + |
| 73 | + // allow showing foreground notifications |
| 74 | + completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); |
| 75 | + // or if you wish to hide all notification while in foreground replace it with |
| 76 | + // completionHandler(UNNotificationPresentationOptionNone); |
| 77 | +} |
| 78 | +``` |
62 | 79 |
|
63 | 80 | ## Android manual Installation
|
64 | 81 |
|
@@ -290,7 +307,7 @@ Notification object example:
|
290 | 307 | foreground: false, // BOOLEAN: If the notification was received in foreground or not
|
291 | 308 | userInteraction: false, // BOOLEAN: If the notification was opened by the user from the notification area or not
|
292 | 309 | message: 'My Notification Message', // STRING: The notification message
|
293 |
| - data: {}, // OBJECT: The push data |
| 310 | + data: {}, // OBJECT: The push data or the defined userInfo in local notifications |
294 | 311 | }
|
295 | 312 | ```
|
296 | 313 |
|
@@ -616,6 +633,12 @@ Available options:
|
616 | 633 |
|
617 | 634 | More information: https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_DEFAULT
|
618 | 635 |
|
| 636 | +## Show notifications while the app is in foreground |
| 637 | + |
| 638 | +If you want a consistent results in Android & iOS with the most flexibility, it is best to handle it manually by prompting a local notification when `onNotification` is triggered by a remote push notification on foreground (check `notification.foreground` prop). |
| 639 | + |
| 640 | +Watch out for an infinite loop triggering `onNotification` - remote & local notification will trigger it. You can overcome this by marking local notifications' data. |
| 641 | + |
619 | 642 | ## Notification while idle
|
620 | 643 |
|
621 | 644 | (optional) Specify `allowWhileIdle` to set if the notification should be allowed to execute even when the system is on low-power idle modes.
|
|
0 commit comments