react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

Need React Native OneSignal background listener for Android & IOS

Open zuhairnaqi opened this issue 3 years ago • 41 comments

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:

  1. install
  2. No listener found for background listener

zuhairnaqi avatar Jan 29 '21 07:01 zuhairnaqi

@rgomezp @gdeglin @leemunroe @keithnoguchi @forki Kindly guide me to resolve this issue. Unable to add background listener.

zuhairnaqi avatar Jan 29 '21 07:01 zuhairnaqi

Facing the same issue on IOS, Please me out I'm stuck last two days :(

syedsaadqamar avatar Jan 29 '21 11:01 syedsaadqamar

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 avatar Jan 29 '21 20:01 rgomezp

@rgomezp yes I've tried to integrate service entension but it never triggers. A helpful PR will be highly appreciated.

zuhairnaqi avatar Jan 30 '21 08:01 zuhairnaqi

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.

unit-002 avatar Mar 01 '21 10:03 unit-002

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.

thenderson55 avatar Mar 20 '21 10:03 thenderson55

Thank you for your patience, we will begin to think about paths towards building this functionality.

rgomezp avatar Mar 30 '21 22:03 rgomezp

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

rgomezp avatar Apr 09 '21 21:04 rgomezp

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

scesbron avatar Apr 12 '21 07:04 scesbron

@rgomezp we need a background notification listener to update state and UI. Because not every user tabs the notification from the top.

zuhairnaqi avatar Apr 12 '21 07:04 zuhairnaqi

@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.

maxbbb avatar Apr 13 '21 19:04 maxbbb

Howdy, Thanks for the info. How did you handle these notifications while the app is swiped away or forced quit?

rgomezp avatar Apr 27 '21 23:04 rgomezp

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.

sumitsk1 avatar Apr 29 '21 10:04 sumitsk1

Any update about this feature? We need onReceived handler so we can handle the video call notifications, or to use callkeep.

anwersolangi avatar May 10 '21 20:05 anwersolangi

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?

anwersolangi avatar Jun 03 '21 07:06 anwersolangi

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.

sumitsk1 avatar Jun 03 '21 08:06 sumitsk1

Howdy, No update quite yet. Thanks for your patience.

rgomezp avatar Sep 18 '21 00:09 rgomezp

@rgomezp sir how much we have to wait for this update???

anwersolangi avatar Sep 18 '21 16:09 anwersolangi

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?

alex-trofimov avatar Sep 30 '21 13:09 alex-trofimov

Did anyone find a way to handle notification in react native app while the app is in the background or killed state?

AvibhavChoudhary avatar Oct 07 '21 06:10 AvibhavChoudhary

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.

bmasisv avatar Oct 07 '21 22:10 bmasisv

Any updates????

parthkanani93 avatar Oct 11 '21 05:10 parthkanani93

Use headless js, FirebaseMessagingService, and foreground services in android. You have to write some native code.

sumitsk1 avatar Oct 11 '21 06:10 sumitsk1

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?

BokiGaja avatar Nov 03 '21 14:11 BokiGaja

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

Dastan4r avatar Nov 04 '21 14:11 Dastan4r

Any updates?

AkeleyUA avatar Nov 10 '21 11:11 AkeleyUA

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.

DanielTBS avatar Nov 22 '21 09:11 DanielTBS

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.

jfishman1 avatar Nov 29 '21 23:11 jfishman1

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.

scesbron avatar Nov 30 '21 07:11 scesbron

@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.

anniewey avatar Dec 24 '21 02:12 anniewey