当应用程序处于后台时,单击通知时不会调用fcm.onNotification()

MEL*_*ENT 4 push-notification cordova ionic2 cordova-plugin-fcm

我已经安装了cordova-plugin-fcm,一切正常,除了一件小事.当应用程序处于后台/关闭状态并且从firebase发送推送通知时,会在设备中弹出通知.从托盘中单击该通知时,我的应用程序开始运行,但控件未进入fcm.onNotification().

app.component.ts中的代码如下所示

   fcm.onNotification().subscribe(data=>{
     if(data.wasTapped){
       console.log("Received in background");
       console.log(data);
     } else {
      console.log("Received in foreground");
      console.log(data);
     };
   });
Run Code Online (Sandbox Code Playgroud)

Geo*_*rge 13

通知应该有"click_action":"FCM_PLUGIN_ACTIVITY"onNotification()被触发,所以如果你从firebase控制台发送它,使用http reqquest发送通知,按照Firebase云消息传递HTTP协议文档形式更多的见解,它将无法工作,我建议Postman到这样做,它也是一个chrome插件.

您的代码应如下所示:

{
  "notification":{
    "title":"Notification title",
    "body":"Notification body",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY", //this is needed so the onNotification() fires when notification is tapped
    "icon":"fcm_push_icon"
  },
  "data":{
    "param1":"value1",
    "param2":"value2"
  },
  "to":"/topics/topicExample"(or device token),
  "priority":"high"
}
Run Code Online (Sandbox Code Playgroud)

引用:

这两个链接拥有你需要的一切

祝好运.