Closed jzonehu closed 1 year ago
you'd better change the plugin to cordova-plugin-firebasex
you'd better change the plugin to cordova-plugin-firebasex
var app = { // Application Constructor initialize: function () { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function () { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function () {
try {
FirebasePlugin.getToken(function (token) {
console.log("Got device token: ", token);
}, function (error) {
console.error(error);
});
FirebasePlugin.onMessageReceived(function (data) {
console.log("Message type: " + data.messageType);
if (data.messageType === "notification") {
console.log("Notification message received");
//primer plano
if (data.tap == "foreground") {
}
//segundo plano
else if (data.tap == "background") {
}
}
console.dir(message);
}, function (error) {
console.error(error);
});
}
catch (e) {
console.log(e);
}
}
};
same result after changing by use cordova-plugin-firebasex
It’s a known issue with how FCM implemented in firebase android sdk. You can only rely on data fields.
When I use onMessage to retrieve information, { "gcm": {"body":"a001a001","title":"A0002","tag":"campaign_collapse_key_708920939448174361"}, "google.message_id":"0:1686131016063685%ba6bfc5fba6bfc5f", "google.sent_time":1686131016055 } it works differently from onBackgroundMessage
{ "google.delivered_priority":"high", "google.sent_time":1686131171758, "google.ttl":2419200, "google.original_priority":"high", "from":"358099810079", "google.message_id":"0:1686131171766807%ba6bfc5fba6bfc5f", "gcm.n.analytics_data":"Bundle[mParcelledData.dataSize=352]", "collapse_key":"com.synct.tccgcm" } ,
resulting in onBackgroundMessage not being able to retrieve the correct information. how can get onMessage whith onBackgroundMessage