FCM with ionic 2 in background not working [closed

2019-02-27 19:49发布

问题:

If my application is closed, after click to notification bar, the callback not working.

It's good in foreground, but not in background.

I use this exemple : https://ionicframework.com/docs/native/fcm/

I test on Andoird

Thanks

回答1:

When app is in background in order to get the click call back you might need to change the notification and data payload sending to the FCM api as below. Here the click_action should be FCM_PLUGIN_ACTIVITY in order to get the click to work properly. Refer the "Send notification. Payload example (REST API)" part in the fcm plugin documentation

{
  "notification":{
    "title":"title",
    "body":"message",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY"
  },
  "data":{
   "title":"title",
    "body":"message",
    "param1":"value1",
    "param2":"value2"
  },
    "to":"token..."
}