wix / react-native-notifications

React Native Notifications
MIT License
3.23k stars 763 forks source link

Notification is not popping up when app is in foreground #891

Closed zahs closed 1 year ago

zahs commented 2 years ago

Platform: ios, Android

Notification is not popping up when app is in foreground. What can be the reason?

JaioSkura commented 2 years ago

same here only in ios

nmengual commented 2 years ago

What is the parameter or configuration for them to be displayed?

devmahmud commented 2 years ago

I am facing similar issue. Any workaround?

josaric commented 2 years ago

Try adding this to AppDelegate.mm for iOS:

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}

docs: https://github.com/react-native-push-notification/ios

zahs commented 2 years ago

@nguyendinhdoan Do you know how it will be possible to enable for Android?

josaric commented 2 years ago

I'll be working on it today or tomorrow and I'll let you know @zahs

for iOS I have added this to my AppDelegate.h

Update AppDelegate.h At the top of the file:

import <UserNotifications/UNUserNotificationCenter.h>

Then, add the 'UNUserNotificationCenterDelegate' to protocols:

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>

and for AppDelegate.mm just follow these docs: https://wix.github.io/react-native-notifications/docs/getting-started#ios

and put this part from my top comment: https://github.com/wix/react-native-notifications/issues/891#issuecomment-1260741637

I have implemented all listeners as they should be, with background and foreground notifications

Screenshot 2022-09-28 at 13 18 21

zahs commented 2 years ago

Perfect thank you :) for iOS it is working already for me.

camboYY commented 1 year ago

android does not work

daveslutzkin commented 1 year ago

This was happening for us but then we realised it was necessary to explicitly handle the notification received foreground event in the react native code:

  Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
    completion({ alert: true, sound: false, badge: false })
  })

Without handling that event like that, no notifications were shown when in the foreground.

josaric commented 1 year ago

This was happening for us but then we realised it was necessary to explicitly handle the notification received foreground event in the react native code:

  Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
    completion({ alert: true, sound: false, badge: false })
  })

Without handling that event like that, no notifications were shown when in the foreground.

I have followed the documentation and everything works correctly.

harendraskd commented 1 year ago
  1. I also follow the doc but I did not get notifications when the android app is in the foreground.Please help us to implement.

  2. In IOS Notification, image are not shown.

stale[bot] commented 1 year ago

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[bot] commented 1 year ago

The issue has been closed for inactivity.