当应用程序在后台运行时,在单击通知时未调用fcm.onNotification() [英] fcm.onNotification() not getting called on clicking the notification when the app is in background

查看:62
本文介绍了当应用程序在后台运行时,在单击通知时未调用fcm.onNotification()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了cordova-plugin-fcm,除了一件小东西,其他所有东西都工作正常.当应用程序在后台/关闭并且从Firebase发送推送通知时,通知会在设备中弹出.从任务栏上单击该通知后,我的应用程序开始运行,但控件未进入fcm.onNotification().

I have installed cordova-plugin-fcm and everything works fine except one little thing. When the app is in background/closed and push notification is sent from firebase, notification pops up in the devices. On clicking that notification from the tray my application starts run, but the control is not entering into fcm.onNotification().

我在app.component.ts中的代码如下

My code in app.component.ts looks like this

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

推荐答案

该通知应具有"click_action":"FCM_PLUGIN_ACTIVITY" ,以便触发onNotification(),因此不会如果您是从Firebase控制台发送邮件,则可以正常工作,请使用http reqquest发送通知,然后按照 Firebase Cloud Messaging HTTP协议文档可以提供更多的见解,我建议邮递员做到这一点,也是chrome插件.

the notification should have "click_action":"FCM_PLUGIN_ACTIVITY" for the onNotification() to be fired, so it would not work if you are sending it from firebase console, send the notification using http reqquest, follow Firebase Cloud Messaging HTTP Protocol documentation form more insights , and i recommend Postman to do it, it is also a chrome plugin.

您的代码应如下:

{
  "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"
}

参考:

Firebase云消息传递HTTP协议

这两个链接具有您所需的一切

those two links have everything you need

祝你好运.

这篇关于当应用程序在后台运行时,在单击通知时未调用fcm.onNotification()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆