Aka*_*han 6 javascript firebase ionic-framework firebase-cloud-messaging
我正在使用带有cordova fcm插件的Ionic框架中的Firebase Notification.我想在用户收到推送通知并点击它时打开一个状态.我正在使用params从Firebase控制台发送通知,但它始终是data.wasTapped false,这就是为什么它不起作用.
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);
});
Run Code Online (Sandbox Code Playgroud)
小智 14
您需要"click_action":"FCM_PLUGIN_ACTIVITY"
根据cordova-plugin-fcm(https://github.com/fechanique/cordova-plugin-fcm)发送有效负载,但在firebase控制台中没有发送此属性的范围.所以你必须手动发送它.
例
//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
}
Run Code Online (Sandbox Code Playgroud)
在Play商店中有一个Android应用程序我发现发送Firebase通知.希望这有助于您发送Firebase通知https://play.google.com/store/apps/details?id=com.learn24bd.fcm
归档时间: |
|
查看次数: |
3371 次 |
最近记录: |