OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.56k stars 373 forks source link

[Bug]: Onesignal does not show notification when app in foreground android #1670

Open AFDHAL2009 opened 5 months ago

AFDHAL2009 commented 5 months ago

What happened?

Hello, i have issue when app in foreground the notif come by silienty , i have installed latest version 5.1.0,but in background works fine .notif come with sound , I dont know if this feature is deleted from this version or no,Note that 4.5.2 works fine .(foreground et backaground) image

 OneSignal.Notifications.requestPermission(true);
  // Method for listening for notification clicks
  OneSignal.Notifications.addEventListener('click', event => {
    console.log('OneSignal: notification clicked:', event);
  });
  OneSignal.Notifications.addEventListener('foregroundWillDisplay', event => {
    console.log('OneSignal: notification foreground:', event);
  });

Steps to reproduce?

1.Install version 5.1.0

What did you expect to happen?

there is no information as notification coming only bye console

React Native OneSignal SDK version

0.70.6

Which platform(s) are affected?

Relevant log output

OneSignal: notification foreground: {"notification": {"actionButtons": undefined, "additionalData": undefined, "androidNotificationId": 1751867923, "bigPicture": undefined, "body": "jhjh", "collapseId": undefined, "fromProjectNumber": "799121433974", "groupKey": undefined, "groupMessage": undefined, "largeIcon": undefined, "launchURL": undefined, "ledColor": undefined, "lockScreenVisibility": 1, "notificationId": "1801dfec-3583-4000-a290-586f0cc26613", "priority": 5, "rawPayload": "{\"google.delivered_priority\":\"normal\",\"google.sent_time\":1711023883965,\"google.ttl\":259200,\"google.original_priority\":\"normal\",\"custom\":\"{\\\"a\\\":{},\\\"i\\\":\\\"1801dfec-3583-4000-a290-586f0cc26613\\\"}\",\"pri\":\"5\",\"vis\":\"1\",\"from\":\"799121433974\",\"alert\":\"jhjh\",\"title\":\"vh\",\"google.message_id\":\"0:1711023884002345%6cef8906f9fd7ecd\",\"google.c.sender.id\":\"799121433974\"}", "smallIcon": undefined, "smallIconAccentColor": undefined, "sound": undefined, "title": "vh"}}

Code of Conduct

RafikMk commented 5 months ago

I'm also experiencing this issue with react-native-onesignal version 5.0.1, where the foregroundWillDisplay event is triggered without actually receiving any notifications when the app is in the foreground. Interestingly, this wasn't an issue in the previous version 4.5.1, where notifications were received as expected under similar conditions. It seems like there might be a change or regression in handling foreground notifications between these versions. Has anyone found a workaround or a fix for this?

monisa-alvi08 commented 5 months ago

Facing the same issue on iOS as well.

samsnori commented 5 months ago

Just noticed this issue which is similar to this: https://github.com/OneSignal/react-native-onesignal/issues/1672 for me the fix I posted there works for Android.