react-native-notifications
react-native-notifications copied to clipboard
Handle callback when notification in background / terminate app
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
Same here , Please provide the fix
I am observing the following:
- On emulator, the notification is shown on foreground and background. HOWEVER, only
registerNotificationReceivedForegroundlogs.registerNotificationReceivedBackgrounddoes 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.
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!
Same problem here in iOS. registerNotificationReceivedBackground does not log.
Any update on this ?
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.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
The issue has been closed for inactivity.