react-native-onesignal
react-native-onesignal copied to clipboard
Need React Native OneSignal background listener for Android & IOS
Description: I want background listener to update status, just like firebase provide us messages().setBackgroundMessageHandler.
One signal version
"react-native-onesignal": "^4.0.3",
Environment Dev
Steps to Reproduce Issue:
- install
- No listener found for background listener
@rgomezp @gdeglin @leemunroe @keithnoguchi @forki Kindly guide me to resolve this issue. Unable to add background listener.
Facing the same issue on IOS, Please me out I'm stuck last two days :(
Howdy, I see RNFirebase has this functionality: https://rnfirebase.io/messaging/usage#message-handlers
I'll mark this as a feature request. Thanks for bringing this up.
In the meantime you will have to use our service extension functionality: https://documentation.onesignal.com/docs/service-extensions
Be prepared to write some native code!
Cheers
@rgomezp yes I've tried to integrate service entension but it never triggers. A helpful PR will be highly appreciated.
I also did try to integrate service extension, though it works in development I am having problem with the release APK all error are pointing to the service extension. It would be nice to have it included in the package instead of creating a new class path.
Yes - this feature is essential for my application. AWS has this feature but one signal seems like a better service. Would rather not have to go back to AWS.
Thank you for your patience, we will begin to think about paths towards building this functionality.
Howdy y'all, In order to contextualize this within our roadmap, we would like to know what use cases would this functionality address? i.e: why do you need this feature?
Cheers
In our app we do two things with our receive listener
- we call an api to our backend to acknowledge the reception of the notification
- we fetch / reset some data so when the use open the notification the fetch is already started
@rgomezp we need a background notification listener to update state and UI. Because not every user tabs the notification from the top.
@rgomezp Just made the switch to v4 and now realizing this issue with not being able to run code when a non-silent notification is received while app is in the background. The solution of using the silent background notifications does not make sense in the context of a notification that needs to display to the user.
An example and our use case is when a user receives a new message notification the message is added to the locally stored messages as soon as the notification is received as an optimistic update so that if a user has notifications on the new messages are immediately available for viewing. I do not see a possible way to do this in v4 and this behavior was working just fine in v3 with the onReceived listener.
Howdy, Thanks for the info. How did you handle these notifications while the app is swiped away or forced quit?
We need same "received" handler / observer in v4 as it was in v3.
OneSignal.addEventListener('received', this.onReceived);
it should trigger even if app is closed or in Background.
Any update about this feature? We need onReceived handler so we can handle the video call notifications, or to use callkeep.
We need same "received" handler / observer in v4 as it was in v3.
OneSignal.addEventListener('received', this.onReceived);
it should trigger even if app is closed or in Background.
saw your comment, any news about the android feature?
As we are using firebase messaging service in one signal. I am using headless js and FirebaseMessagingService. I have created a foreground service in android which will run even if the app is closed from the backgrround. It is working fine on android.
Howdy, No update quite yet. Thanks for your patience.
@rgomezp sir how much we have to wait for this update???
We used to have OneSignal v3 in our project and we depended on the ability to react to background notifications. Then we had to update one of our crucial libs and we encountered a conflict that is similar to this: https://github.com/OneSignal/react-native-onesignal/issues/565. In order to resolve it, we had to update OneSignal to v4 and now background notifications can't be handled and we have to look into workarounds.
@rgomezp any chance you'll bring this ability back?
Did anyone find a way to handle notification in react native app while the app is in the background or killed state?
Since january this it's reported..?... at least would you add a example of the Android Notification Service Extension? to address this issue? im using react native and this a big stopper to my customer.
Any updates????
Use headless js, FirebaseMessagingService, and foreground services in android. You have to write some native code.
I have the same issue with the 4.3.1
version. Notifications are properly handled when the app is open or in the background, but once it is closed and in "killed state" tapping on the notification doesn't even open the app. Does anybody have any advice?
Same in 4.3.1. I need update my bottom tab even if notification received in background, but in 4.3.1. i cant do this. So please provide some background handler for this
Any updates?
Howdy, No update quite yet. Thanks for your patience.
Hello Rodrigo,
how long do companies should pay for service and not get the most out of it? this issue has been for quite a long time. can we please address this issue and solve it as soon as possible? quite long time we are waiting for this fix.
Hi everyone, for React Native to handle notification payloads received while the app is in the background, you will need to implement a Native Module. We have a guide on this here: https://documentation.onesignal.com/docs/rn-android-native-module-setup-for-notification-service-extension
The native module will then trigger the service extension which can pass the data to the RN app.
The OneSignal SDK has never had the ability to handle notification received events while the app is in the background. You will need to implement the Native Module to handle this.
We will take this into consideration as a Feature Request. Thank you.
Thank for the help and the link. I just want to mention that I do not agree with you when you say that the SDK has neved had the ability to handle notification received while the app is in the background.
On our side with stick with version 3 of the sdk because it works with this version but not with version 4. For me it's not really a feature request but a regression between v3 and v4.
@jfishman1 I've implemented the service extension and tested notification display in fg, bg and killed state.
I set notificationReceivedEvent.complete(null)
in NotificationServiceExtension.java
and the following behaviour was observed in Android:
foreground: no notification display, receive payload in App.js
background: no notification display, receive payload in App.js
killed: notification display, did not receive payload in App.js
Can I know why in killed state, the notification still display? Does it not trigger the service extension? I understand that when app is killed, RN module will not be initialized so couldn't pass the notification data to App.js. I supposed the notification will not be displayed.
I'm trying to find a workaround to handle notification if user manually cleared app data without logging out, causing notification still be sent to the device.
Update:
Previously I was using normal push. So I tried with "content_available": "true"
, and found out it behaves correctly (not showing notification when killed) since it's 'silent' push. Now the dilemma is handling the logic from native code. 😓 Just wondering can we control the push display from App.js if using NotificationServiceExtension? Sorry, I'm not familiar in native code.