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);
});
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With