Ionic - Push notification. Method fcm.onNotification not work when app is open/running

余生长醉 提交于 2019-12-08 08:10:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!