5

Im using React Native Push Notification https://github.com/zo0r/react-native-push-notification Currently, it will receive push notification after closing the app.

  1. How can I pass my pushMessage(chat) into the notification?

  2. How to make it receive push notification in foreground (when the app still open) and background (without opening the app) *currently it will receive the notification after closing the app

which part should I work on?

App.js
--------
PushNotification.configure({
    // (required) Called when a remote or local notification is opened or received
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );

        // process the notification . * this will overwrite the My Notification 1 below
        PushNotification.localNotification({
            foreground: true,
            title: "My Notification Title",
            message: "My Notification 2", // (required)
        });

        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },


});


class App extends Component{
    componentDidMount(){
        const connection = signalr.hubConnection('https://api.abc.com');
        const proxy = connection.createHubProxy('chatHub');

        proxy.on('pushMessage', (chat) => {
            PushNotification.localNotification({
               foreground: true,
               title: "My Notification Title",
               message: "My Notification 1", // (required)
            });
        });
    }
}
keatwei
  • 247
  • 8
  • 17

0 Answers0