2

I have a local notification with action buttons 'Start' and 'Remind later'. When I click on either of two, the app opens. I want to keep it for the Start button, but for Remind later button I want to silently run some code (reschedule notification on a later time) without opening an app.

Is this possible to do?

    function onOpened(notification) {
        if (notification.action == 'Start') {
            cancelNotification(notification.id)
            NavigationService.navigate(notification.title)
        } else {
            cancelNotification(notification.id)
            // reschedule
            let dateTime = new Date(notification.fireDate)
            dateTime.setMinutes(dateTime.getMinutes() + 30)
            scheduleNotification(notification.id, notification.title, notification.message, dateTime)
    }
}

This code works, but as I said, it bring the app to the foreground, and I'd like to avoid it.

irondsd
  • 1,140
  • 1
  • 17
  • 34

1 Answers1

1

You need to include your full code if you looking for help, but from your tags, I assume you are using React Native Push Notifications. If that's the case you might want to look at this Action click brings the app from background to foreground issue. Basically, you need to go through some native codes and change a few lines.

DNA.h
  • 823
  • 8
  • 17
  • 1
    Can you be more specific what do I need to change and where? I followed your link and there's a commit of an older version saying they fixed it. I have a newer version and I still see this behavior. – irondsd Apr 23 '19 at 10:41
  • You can either A) uninstall the current version of react-native-push-notifications and install version 3.1.1. or earlier or B) change RNPushNotificationHelper.java according to this link https://github.com/zo0r/react-native-push-notification/commit/6b732623c62f3b4fdbcc47aa786556ae23da17a7. I personally prefer later choice since I'm used to manually changing files according to my needs – DNA.h Apr 23 '19 at 10:53
  • I have a question, I'm developing two apps first of the user app and second to providers, in user app, I made some function to send order and saved into real-time database firebase t and in the second app I just retrieve the data from DB with a listener to get the new order as a real-time without refreshing the app, SO I want to when I send an order from user app to firebase I want to display a notify in the second app? How to handle these – DevAS May 14 '19 at 05:30
  • @DevAS this is a very easy task if you are using firebase database too. You might check this https://stackoverflow.com/questions/38022413/firebase-notification-on-child-added-modified or https://firebase.google.com/docs/functions/use-cases – DNA.h May 14 '19 at 06:31