Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS cannot receive first push notification when open in foreground #508

Closed
samchanCHS opened this issue Feb 21, 2020 · 15 comments
Closed

iOS cannot receive first push notification when open in foreground #508

samchanCHS opened this issue Feb 21, 2020 · 15 comments
Assignees

Comments

@samchanCHS
Copy link

samchanCHS commented Feb 21, 2020

Version: 3.1.2
RN version: 0.61.5

Using this version and lines from documentation

Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
      console.log("Notification Received - Foreground", notification.payload);

      // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
      completion({alert: true, sound: true, badge: false});
        });

I can only see the push notification alert starts from 2nd push notification, but not the first one.

@samchanCHS
Copy link
Author

My current fix:

  1. Downgrade to 3.1.1
  2. In AppDelegate.m
  • make it conform to UNUserNotificationCenterDelegate
  • add a line [RNNotifications addNativeDelegate:self]; in didFinishLaunchingWithOptions
  • add a function:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}

@samchanCHS
Copy link
Author

samchanCHS commented Feb 21, 2020

BTW, I think the file causing this issue should be RNNotificationCenterMulticast.m

@roni-castro
Copy link

roni-castro commented Mar 16, 2020

I am also facing the exactly same problem on react-native-notifications: 3.1.2 and react-native 0.60
@samchan1995 I have downgraded to 3.1.1 and added the userNotificationCenter function, but I still have this problem. Can you share your AppDelegate?

@stale
Copy link

stale bot commented Apr 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Apr 17, 2020
@stale
Copy link

stale bot commented Apr 25, 2020

The issue has been closed for inactivity.

@stale stale bot closed this as completed Apr 25, 2020
@zoftify
Copy link

zoftify commented Apr 30, 2020

Hi @samchan1995, the issue is still there :( Can you please share the way you solved that?

Much appreciated!

@ALPNP
Copy link

ALPNP commented May 8, 2020

The @samchan1995 implementation works for me on version 3.1.1. Do you still need the AppDelegate file ?

RN version: 0.61.4

@focux
Copy link

focux commented May 11, 2020

It's also happening to me but I don't think that downgrade should be the solution. I'll try to track this down.

RN version: 0.61.5
RN Notifications: 3.1.4

@focux
Copy link

focux commented May 11, 2020

To fix this bug in RN notifications 3.1.4, go first to RNNotificationsStore.m, then find the initializer and apply this changes (you can also apply this patch using patch-package):

 diff --git a/node_modules/react-native-notifications/lib/ios/RNNotificationsStore.m b/node_modules/react-native-notifications/lib/ios/RNNotificationsStore.m
index d5e953a..18075da 100644
--- a/node_modules/react-native-notifications/lib/ios/RNNotificationsStore.m
+++ b/node_modules/react-native-notifications/lib/ios/RNNotificationsStore.m
@@ -16,8 +16,13 @@ + (instancetype)sharedInstance {
 
 - (instancetype)init {
     self = [super init];
-    _actionCompletionHandlers = [NSMutableDictionary new];
-    _presentationCompletionHandlers = [NSMutableDictionary new];
+    if (!_actionCompletionHandlers){
+        _actionCompletionHandlers = [NSMutableDictionary new];
+    }
+    
+    if (!_presentationCompletionHandlers) {
+        _presentationCompletionHandlers = [NSMutableDictionary new];
+    }
     return self;
 }

I won't put together a PR because it seems that the maintainers are not accepting/reviewing PRs, however, if @yogevbd is willing to review it, I'll be glad to do it.

@cmrigney
Copy link

cmrigney commented May 28, 2020

Any updates on this? I'm experiencing the same issue. I'm on v3.2.2.

@nerdmv
Copy link

nerdmv commented Jul 9, 2020

My current fix:

  1. Downgrade to 3.1.1
  2. In AppDelegate.m
  • make it conform to UNUserNotificationCenterDelegate
  • add a line [RNNotifications addNativeDelegate:self]; in didFinishLaunchingWithOptions
  • add a function:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}

this is actually worked :/

@fedu44
Copy link

fedu44 commented Jul 22, 2020

Same problem

@yogevbd yogevbd self-assigned this Jul 23, 2020
@yogevbd yogevbd reopened this Jul 23, 2020
@stale
Copy link

stale bot commented Aug 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the 🏚 stale label Aug 22, 2020
@lukeramsden
Copy link

lukeramsden commented Aug 26, 2020

Not stale. Is a fix live yet?

@stale stale bot removed the 🏚 stale label Aug 26, 2020
@kostiantyn-solianyk
Copy link

kostiantyn-solianyk commented Sep 17, 2020

When you set this - [RNNotifications addNativeDelegate:self]; you will not be able to get notification from event listener Notifications.events().registerNotificationOpened that method will not trigger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants