Yogendra Girase
Yogendra Girase

Reputation: 631

React-native Pushy notification in Android

I have implemented pushy notification in my react-native project following below link: https://pushy.me/docs/additional-platforms/react-native

I am facing problem on Android, I am getting the notification but on clicking on notification from the notification bar, I am not getting any callback or control on react-native method => Pushy.setNotificationListener

According to documentation, we have to get the call in Pushy.setNotificationListener method.

Please let us know how to proceed in this as soon as possible.

Upvotes: 1

Views: 562

Answers (1)

Elad Nava
Elad Nava

Reputation: 7896

You may now call the Pushy.setNotificationClickListener((data) => {}) method from your application to listen for when the user clicks your notifications:

// Listen for push notifications clicked
Pushy.setNotificationClickListener(function (data) {
    // Display basic alert
    alert('Clicked notification: ' + data.message);

    // Navigate the user to another page or 
    // execute other logic on notification click
});

This method is now supported on both Android and iOS. Inside this method, you can then check the notification payload which was clicked and direct the user to the relevant page in your RN app.

To be able to access this method, please update the Pushy RN SDK by running the following commands in the root of your RN project:

npx react-native unlink pushy-react-native
npm install pushy-react-native@latest --save
npx react-native link pushy-react-native

Next, update the versions imported in android/app/build.gradle:

// Pushy SDK for Android
compile 'me.pushy:sdk:1.0.53'

// Pushy SDK for React Native Android
compile 'me.pushy:sdk-react-native:1.0.12'

Also, modify your Pushy.notify() invocation to include a third parameter:

Pushy.notify(notificationTitle, notificationText, data);

Good luck!

Upvotes: 1

Related Questions