question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Action, onNotification not working with localNotification

See original GitHub issue

Hi and thanks for your work

I can’t get Action working, and even the onNotification parameter notify nothing.

Here is the code i put in my App.js componentDidMount there is the configuration and the action handler

 componentDidMount() {
    PushNotification.configure({
      // (required) Called when a remote or local notification is opened or received
      onNotification: function(notification) {
        console.log('NOTIFICATION:', notification);
      },
      popInitialNotification: true,
      requestPermissions: true,
    });

    (function() {
      PushNotificationAndroid.registerNotificationActions(['Lire']);
      DeviceEventEmitter.addListener('notificationActionReceived', function(
        action,
      ) {
        console.log('Notification action received: ' + action);
        const info = JSON.parse(action.dataJSON);
        if (info.action === 'Lire') {
          console.log('do the action');
        }
        // Add all the required actions handlers
      });
    })();
  }

here is my function that i call to receive notification

const registerLocalNotification = article => {
  const titre = he.decode(article.titre); 
  PushNotification.setApplicationIconBadgeNumber(0);
  PushNotification.localNotification({
    /* Android Only Properties */
    vibrate: true,
    vibration: 300,
    priority: 'high',
    visibility: 'public',
    importance: 'high',

    /* iOS and Android properties */
    title: 'nouvel article',
    message: titre, // (required)
    playSound: false,
    number: 1,
    actions: '["Lire"]',
  });
};

The notifications work fine but:

  • when I click on the action button (on the notification message). Nothing is happening. I can’t see the console.log() in the DeviceEventEmitter.addListener method
  • i can’t even see the console.log(‘NOTIFICATION:’, notification); in the PushNotification.configure method

My configuration is: react-native-cli: 2.0.1 react-native: 0.61.4 debian 10 and i test on emulated device with Android 9

Can someone tell me what do i miss ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

12reactions
zaidpathanGitcommented, Dec 27, 2019

Finally after changing some code directions. I made it work so sharing the code and have a look on it might helpful to you 😃

`var PushNotification = require(“react-native-push-notification”);

export class Participant extends React.Component {

componentWillMount() {
    PushNotification.configure({
        onNotification: (notification) => {

            //Code to print array into console
            console.log(notification);

            //Code to be executed according to the action selected by the user
            if (notification.action == "Copy ID") {
                Clipboard.setString('hello id');
            }
            else if (notification.action == "Copy Password") {
                Clipboard.setString('hello password');
            }
        },
        popInitialNotification: true,
        requestPermissions: true,
    });
}

//Function to generate count down timer
generateCountdownTimer = (index, eventDate, eventTime) => {

            return <CountDown style={{ marginBottom: 5, }} until={eventTimeIntoSeconds} size={17}
                onFinish={() => {

                    //Code to display push notification to the user into status bar
                    PushNotification.localNotification({
                        id: index,
                        largeIcon: "ic_launcher",
                        title: "1 new notification",
                        message: //Your msg here
                        vibrate: true,
                        vibration: 300,
                        priority: "high",
                        actions: '["Copy ID", "Copy Password"]',

                    });
                }
                } />
        }

}`

0reactions
Dallas62commented, Aug 22, 2021

Hi @odnarb

Posting a single quote of code will not help to reproduce since it’s depend on many configuration (such as AndroidManifest, MainActivity, AppDelegate, …) Try to find the difference between exemple project or provide a reproducible exemple from exemple project.

As you may read in issues, this repository is open for maintainers, feel free to ask for it. I do not have enough time to maintain this project actually.

Regards

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native Push Notification onNotification event not working
for those asking for a solution, I did something like this in my app.js's componentDidMount method:
Read more >
react-native-push-notification - npm
Read the troubleshooting guide before raising an issue. ... or local notification is opened onNotification: function (notification) ...
Read more >
Sometime tapping on notification's… | Apple Developer Forums
Sometime tapping on notification's action button is not firing ... forLocalNotification: (UILocalNotification*) localNotification { //handle action here.. }.
Read more >
How to use the react-native-push-notification.configure ... - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix ... when a remote or local notification...
Read more >
Implementing React Native Push Notifications in Android Apps
Do note that, if you are not looking forward to using remote ... when a remote or local notification is opened or received...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found