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

Need React Native OneSignal background listener for Android & IOS #1154

Open
zuhairnaqi opened this issue Jan 29, 2021 · 42 comments
Open

Need React Native OneSignal background listener for Android & IOS #1154

zuhairnaqi opened this issue Jan 29, 2021 · 42 comments
Assignees

Comments

@zuhairnaqi
Copy link

zuhairnaqi commented Jan 29, 2021

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

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

@syedsaadqamar
Copy link

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

@rgomezp
Copy link
Contributor

rgomezp commented Jan 29, 2021

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

@zuhairnaqi
Copy link
Author

zuhairnaqi commented Jan 30, 2021

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

@unit-002
Copy link

unit-002 commented Mar 1, 2021

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.

@thenderson55
Copy link

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.

@rgomezp
Copy link
Contributor

rgomezp commented Mar 30, 2021

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

@rgomezp
Copy link
Contributor

rgomezp commented Apr 9, 2021

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

@scesbron
Copy link

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

@zuhairnaqi
Copy link
Author

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

@maxbbb
Copy link

maxbbb commented Apr 13, 2021

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

@rgomezp
Copy link
Contributor

rgomezp commented Apr 27, 2021

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

@sumitsk1
Copy link

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.

@anwersolangi
Copy link

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

@anwersolangi
Copy link

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?

@sumitsk1

This comment has been minimized.

@rgomezp
Copy link
Contributor

rgomezp commented Sep 18, 2021

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

@anwersolangi
Copy link

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

@alex-trofimov
Copy link

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: #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?

@AvibhavChoudhary
Copy link

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

@bmasisv
Copy link

bmasisv commented Oct 7, 2021

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.

@parthkanani93
Copy link

Any updates????

@sumitsk1
Copy link

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

@BokiGaja
Copy link

BokiGaja commented Nov 3, 2021

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?

@Dastan4r
Copy link

Dastan4r commented Nov 4, 2021

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

@AkeleyUA
Copy link

Any updates?

@DanielTBS
Copy link

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.

@jfishman1
Copy link

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.

@scesbron
Copy link

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.

@anniewey
Copy link

anniewey commented Dec 24, 2021

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

@tedekeroth
Copy link

As @scesbron, @zuhairnaqi and others have said, we have similar use-cases:

  • We send notifications, and we need a delivery ack when the device has received it and a notification has been shown
  • The OneSignal API (backend to backend) can give you delivery information, but that delivery information almost always says "delivered", but the user has not seen a notification
  • By letting the device itself ACK the push, we at least know it was delivered and if a notif isnt shown then, we for sure know that it is our code that somehow stop the notif som displaying

So, the func to trigger a callback to our code, so we can send an ACK, is very important for us.

@OkancanCosar
Copy link

any update?

@scesbron
Copy link

Just to notice that I am now stucked. I was keeping the v3 version because of this problem but I had to update my app to react-native 0.68 and add support for Android 12 (sdk31) but now I face another bug that apparently can only be solved by updating to the latest version: https://github.com/OneSignal/react-native-onesignal/releases/tag/4.3.2

@sumitsk1
Copy link

sumitsk1 commented Sep 8, 2022

Since 29 Jan 2021, still no update for this feature.

@shamique
Copy link

When can we expect an update for this ? 😞

@shamique
Copy link

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

Did this work ? Tried this approach, but NotificationEvent in front end never gets trigger. Any idea ?

@dipendra-sharma
Copy link

Hi, Anyone find any solution for this ?

@bwoodlt
Copy link

bwoodlt commented Oct 26, 2023

Interested in this feature, does anyone have an update or got the native part working?

@tuugi0113
Copy link

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

not work what so why.

@eduardojigub
Copy link

The year is 2024 and i have the same problem here, any workaround ?
The documentation for the Service Extension doesn't trigger the console.log here.

@FreTimmerman
Copy link

FreTimmerman commented May 6, 2024

Everywhere i look. Some people keep saying "you will have to write Native code", and sure i understand this.

Is there somewhere an example or guide on how/what to write?
closest example i found is #1435 but i'm not sufficient enough in native code to understand what i'm supposed to implement vs what i'm supposed to change for my own

and the guide mentioned by @jfishman1 is no longer available

EDIT:

I have found the following NPM package (mentioned by https://www.npmjs.com/package/react-native-push-notification which itself is mentioned in the React Native docs)

https://www.npmjs.com/package/@react-native-community/push-notification-ios

and i can confirm that this works for receiving silent background notifications sent by OneSignal (either by OneSignal UI or the node API), though i have only tried for iOS.
I suppose that the general NPM package would work also for android...

@bitshadow
Copy link

bitshadow commented Aug 20, 2024

I suppose that the general NPM package would work also for android...

For android the general package may work only if they are using firebase messaging.

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

No branches or pull requests