我在fcm.onNotification
中遇到问题。但就我而言,我会在应用程序处于后台时收到通知。
但是当我点击通知时,不会调用onNotification处理程序(应用程序正在打开,但onNotification没有响应)。当应用程序处于活动状态时,将调用onNotification处理程序。
信息:-以前,我在fcm插件中遇到问题,所以我在插件中做了一些更改:
in-> /plugins/cordova-plugin-fcm-with-dependecy-updated/src/android/FCMPlugin.gradle
compile 'com.google.firebase:firebase-core:11.4.2'
和-> /platforms/android/project.properties
cordova.system.library.3=com.google.firebase:firebase-core:11.4.2
cordova.system.library.4=com.google.firebase:firebase-messaging:11.4.2
cordova.system.library.7=com.google.android.gms:play-services-auth:11.4.2
cordova.system.library.8=com.google.android.gms:play-services-identity:11.4.2
app.component.ts中的我的代码
this.fcm.onNotification().subscribe(data => {
console.log(JSON.stringify(data));
console.log(JSON.stringify(this.fcm));
if(data.wasTapped){
console.log("Received in background data.wasTapped");
console.log(JSON.stringify(data));
} else {
console.log("Received in foreground");
};
});
使用Firebase云功能发送有效载荷:
dataString = '{"to": "'+token+'","notification":{"title":"Message","body":"From '+eId+'","sound":"default"},"data":{"notificationKey":"'+ key +'","goto":"messageForBidder","evid":"'+eventId+'","id":"'+id+'"},"click_action":"FCM_PLUGIN_ACTIVITY","icon":"fcm_push_icon"}';