3

我在使用cordova fcm插件的离子框架中使用Firebase通知。我想在用户收到推送通知并点击它时打开一个状态。我使用params发送来自Firebase控制台的通知,但它始终是data.was已跳过错误,这就是为什么它不起作用。离子FCM始终为空

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); 
}); 

回答

7

您需要在您的有效载荷发送"click_action":"FCM_PLUGIN_ACTIVITY"根据科尔多瓦 - 插件-FCMhttps://github.com/fechanique/cordova-plugin-fcm),但在火力控制台是没有范围发送此属性。所以你必须手动发送它。

//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 
} 

在Play商店中有一个Android应用程序,我发现送火力地堡通知。希望这将有助于你发送通知火力地堡https://play.google.com/store/apps/details?id=com.learn24bd.fcm

+0

当我将在有效载荷通知阵列,我已经收到两份通知 – Sakshi

+0

@Adam史密斯: - 我已经申请了,还是同样的问题 –

+0

@Adam非常感谢,你拯救我的生命:) –