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

Handle callback when notification in background / terminate app #1037

Open
muslimmuda15 opened this issue May 21, 2024 · 6 comments
Open

Handle callback when notification in background / terminate app #1037

muslimmuda15 opened this issue May 21, 2024 · 6 comments

Comments

@muslimmuda15
Copy link

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
Copy link

Same here , Please provide the fix

@coyotespike
Copy link

coyotespike commented Jul 18, 2024

I am observing the following:

  • On emulator, the notification is shown on foreground and background. HOWEVER, only registerNotificationReceivedForeground logs. registerNotificationReceivedBackground does not log.
  • A colleague testing on hardware sees notifications on foreground, not on background.

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
Copy link

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
Copy link

khalilpan commented Sep 4, 2024

Same problem here in iOS. registerNotificationReceivedBackground does not log.

@nlabofa
Copy link

nlabofa commented Oct 19, 2024

Any update on this ?

@van8tka
Copy link

van8tka commented Nov 22, 2024

Hi! I have the same problem on android, but I found that if send message with only field "data"(without "notification" field) I can handle callback when app in background, but if app terminate it not worked! If exist "notofication" field, I can't handle in background and terminate mode.
for ex send throught postman+firebase:

{
    "message":{
        "token":"xxx",
        "data": {
            "text": "Hello!"
        }
    }
}

Any solutions?

PS If I override FcmService on native, I can handle all message on all modes in onMessage method but then Notifications.events().. can't work.

PS2 I understood the problem. It's can't work when app terminated because rn-notification need React Context but if app terminated ReactContext is null and then method on JS can't fire from native code.

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

No branches or pull requests

6 participants