wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

Handle callback when notification in background / terminate app #1037

Open muslimmuda15 opened 6 months ago

muslimmuda15 commented 6 months ago

How to handle callback when Notificationin background?

I have put the code into index.js

// ...
Notifications.events().registerNotificationReceivedForeground(
  (notification, completion) => {
    console.log(
      `Notification received in foreground: ${notification.title} : ${notification.body}`,
    );
    completion({ alert: false, sound: false, badge: false });
  },
);

Notifications.events().registerNotificationReceivedBackground(
  (notification, completion) => {
    console.log(
      `Notification received in background: ${notification.title} : ${notification.body}`,
    );
    completion({ alert: false, sound: false, badge: false });
  },
);

The Notifications.events().registerNotificationReceivedForeground cllback in working well. when I using Notifications.events().registerNotificationReceivedBackground the notif is successful to show in background / terminate, but I cannot getting any callback in my log. Please help

SwapnilRathore commented 5 months ago

Same here , Please provide the fix

coyotespike commented 4 months ago

I am observing the following:

This is on v5.1.0. Really puzzling.

I have set <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> in all AndroidManifest, but this was already present in debug build and did not change anything.

I also ensured that playImplementation "com.google.firebase:firebase-messaging:23.3.1", not core, was present.

coyotespike commented 3 months ago

Just to bump this: this bug appears to be related to a lack of push notifications on Android API 33 and above, when the app is in the background. If anyone has any ideas I am happy to debug further!

khalilpan commented 2 months ago

Same problem here in iOS. registerNotificationReceivedBackground does not log.

nlabofa commented 1 month ago

Any update on this ?