问题
I have a ionic app (v4). I want send push notification. I use cordova-plugin-fcm-with-dependecy-updated plugin and @ionic-native/fcm dependency.
In app.component.ts I have:
initializeApp() {
this.plt.ready().then(() => {
this.fcm.onNotification().subscribe(data => {
console.log(data)
});
});
}
I send a push notification:
POST https://fcm.googleapis.com/fcm/send
headers:
Content-Type: application/json
Authorization: key=my-key
body:
{
"notification":{
"title":"My Title",
"body":"My body",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"notificationType":"MATCH_CONFIRMATION",
"matchId":"123"
},
"condition":"'match_dev_confirmation_81' in topics",
"priority":"high",
"restricted_package_name":""
}
The notification always arrives, and when I press on the notification and app is closed, the method fcm.onNotification() is called and the app opens correctly. But, when I press on the notification and the app is open/running the method fcm.onNotification() is not called.
Is this the right behavior? Is there any way that when I press the notification and the application is open, the method fcm.onNotification() is called?
来源:https://stackoverflow.com/questions/58418159/ionic-push-notification-method-fcm-onnotification-not-work-when-app-is-open-r