Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic FCM wasTapped always false

I am using Firebase Notification in Ionic framework with cordova fcm plugin. I want to open a state when user received push notification and tapped it. I am sending notification from Firebase console with params but It's always data.wasTapped false that's why it does not work.

FCMPlugin.onNotification(function(data) 
{
    if (data.wasTapped) {
        //Notification was received on device tray and tapped by the user.
        console.log("Tapped: " + JSON.stringify(data));
        if (data.hasOwnProperty('state')) {
            $timeout(function(){
                $state.go(data.state);
            })

        }

    } 
    else 
    {
        //if user already opened app
        console.log("Not tapped: " + JSON.stringify(data));
    }
}, function(msg) {
    console.log('onNotification callback successfully registered: ' + msg);
}, function(err) {
    console.log('Error registering onNotification callback: ' + err);
});
like image 413
Akash khan Avatar asked Nov 28 '16 06:11

Akash khan


1 Answers

You need to send "click_action":"FCM_PLUGIN_ACTIVITY" in your payload according to cordova-plugin-fcm (https://github.com/fechanique/cordova-plugin-fcm) but in the firebase console there is no scope to send this property. So you have to send it manually.

Example

//POST: https://fcm.googleapis.com/fcm/send
//HEADER: Content-Type: application/json
//HEADER: Authorization: key=AIzaSy*******************
{
  "notification":{
    "title":"Notification title",  //Any value
    "body":"Notification body",  //Any value
    "sound":"default", //If you want notification sound
    "click_action":"FCM_PLUGIN_ACTIVITY",  //Must be present for Android
    "icon":"fcm_push_icon"  //White icon Android resource
  },
  "data":{
    "param1":"value1",  //Any data to be retrieved in the notification callback
    "param2":"value2"
  },
    "to":"/topics/topicExample", //Topic or single device
    "priority":"high", //If not set, notification won't be delivered on completely closed iOS app
    "restricted_package_name":"" //Optional. Set for application filtering
}

In the play store there is an android app I have found to send Firebase Notification. Hopefully this will help you to send Firebase Notification https://play.google.com/store/apps/details?id=com.learn24bd.fcm

like image 98
Adam Smith Avatar answered Oct 22 '22 08:10

Adam Smith