Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 3ad9182

Browse files
author
Boris Tacyniak
authored
Merge pull request #1847 from vaibhavhrt/vaibhavhrt-patch-1
Remove redundant import statement
2 parents e1a3f3d + bf4fccb commit 3ad9182

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# React Native Push Notifications
1+
# React Native Push Notifications
22

33
[![npm version](https://badge.fury.io/js/react-native-push-notification.svg?update=9)](http://badge.fury.io/js/react-native-push-notification)
44
[![npm downloads](https://img.shields.io/npm/dm/react-native-push-notification.svg?update=9)](http://badge.fury.io/js/react-native-push-notification)
@@ -56,9 +56,26 @@ Having a problem? Read the [troubleshooting](./trouble-shooting.md) guide before
5656

5757
## iOS manual Installation
5858

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).
6060

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+
```
6279

6380
## Android manual Installation
6481

@@ -290,7 +307,7 @@ Notification object example:
290307
foreground: false, // BOOLEAN: If the notification was received in foreground or not
291308
userInteraction: false, // BOOLEAN: If the notification was opened by the user from the notification area or not
292309
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
294311
}
295312
```
296313

@@ -616,6 +633,12 @@ Available options:
616633

617634
More information: https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_DEFAULT
618635

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+
619642
## Notification while idle
620643

621644
(optional) Specify `allowWhileIdle` to set if the notification should be allowed to execute even when the system is on low-power idle modes.

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import androidx.annotation.RequiresApi;
2929
import androidx.core.app.NotificationCompat;
3030

31-
import androidx.annotation.RequiresApi;
32-
import androidx.core.app.NotificationCompat;
33-
3431
import com.facebook.react.bridge.Arguments;
3532
import com.facebook.react.bridge.ReadableArray;
3633
import com.facebook.react.bridge.ReadableMap;

0 commit comments

Comments
 (0)