React-native-onesignal: Need React Native OneSignal background listener for Android & IOS

Created on 29 Jan 2021  路  16Comments  路  Source: OneSignal/react-native-onesignal

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
  • Enhancement / Feature

    Most helpful comment

    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.

    All 16 comments

    @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 It's working when app is open even if in background but when app is killed from recent apps then it's not working , but in debug mode even if app is killed its working .
    We need to create Some kind of background service which will run in background even if the app is killed then it will work fine.
    (I tried using notification listener service just to run the app in background and it's working fine in every condition.)
    I don't have much knowledge of java and how background services work in android.

    Was this page helpful?
    0 / 5 - 0 ratings