Open app when push notification is clicked


#1

Earlier I implemented push notification using fcm, I send the notification from my server to the mobile which works fine.

The problem
When the push notification arrives on my phone, When I click on it, I expect it to open the application instead it dismisses the notification and that’s all.

My Observation
After different test I could notice that once I change the data property from the notification payload from on server from data to notification it works(Once notification is clicked app opens) but the problem with this is that, the app doesn’t make sound or vibrate neither thise is show my action button.

This is a snippet of code I used in sending the push notification

var FCM = require('fcm-node');
var fcm = new FCM(serverKey);
var serverKey = require('path-to-server-key.json');

exports.pushNotification = (data) => {
    var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera) 
        to: data.push_token,\\\

        /**
*notification:{ //This opens the application but doesn't perform other action
            *"title":"title"
         *};
**/

        data: {  //Using data works fine but app doesnt open when notification clicked
            title: data.name,
            body: data.message,
            soundname: "default",
            "iconColor": "purple",
            "image-type": "circle",
            image: 'www/assets/icon/icon.png',
            summaryText: 'You have a new message',
            ledColor: "[0, 0, 255, 0]",
            vibrationPattern: "[100, 500]",
            "force-start": '1',
            actions: '[ { "title": "Reply", "callback": "app.replyMessage", "foreground": "false", "inline": "true" }]'
        }
    }

    fcm.send(message, function (err, response) {
        if (err) {
            console.log("Something has gone wrong!", err)
        } else {
            console.log("Successfully sent with response: ", response)
        }
    })
}

And in my mobileApp I have this

pushNotification() {
//After impoerting the push noification plugin
    this.push.hasPermission()
      .then((res: any) => {

        if (res.isEnabled) {
         console.log("Permission granted");
        } else {
          console.log('No permission for notification');
        }

      });

    const options: PushOptions = {
      android: {
        senderID: 'my-sender-id',
        sound: true,
        iconColor:"purple",
        vibrate: 'true',
        forceShow: 'true'
      },
      ios: {
        alert: 'true',
        badge: true,
        sound: 'false'
      },
      windows: {}
    };

    const pushObject: PushObject = this.push.init(options);

    pushObject.on('notification').subscribe((notification: any) => {
      console.log('Received a notification', notification);
    });

    pushObject.on('registration').subscribe((registration: any) => {
      //update user token
console.log(registration.registrationId);
    });
    pushObject.on('error').subscribe(error => {
      console.error('Error with Push plugin', error);
    });
  }

Kindly assist if you have implemented this before. How can I open the app when push notification is click on