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非常感謝,你拯救我的生命:) –