【问题标题】:Accessing FCM parameters by toastr通过 toastr 访问 FCM 参数
【发布时间】:2019-01-07 14:19:11
【问题描述】:

我通过 FCM 收到以下 JSON 格式的通知:

    {
      "message":{
        "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
        "notification":{
          "title":"Portugal vs. Denmark",
          "body":"great match!"
        },
        "data" : {
          "Nick" : "Mario",
          "Room" : "PortugalVSDenmark"
        }
      }
    }

我可以使用payload.notification.title 访问通知标题和正文,如下面的代码所示。 但是如何访问 data 部分中的其他参数?

// Handle incoming messages
messaging.onMessage(function(payload) {
  console.log("Notification received: ", payload);
  toastr["success"](payload.notification.body, payload.notification.title, {
      "closeButton": true,
      "debug": false,
      "newestOnTop": false,
      "progressBar": true,
      "positionClass": "toast-top-left",
      "onclick": payload.notification.click_action, // I also tried removing this
      "preventDuplicates": false,
      "showDuration": 30000,
      "hideDuration": 1000,
      "timeOut": 0,
      "extendedTimeOut": 0,
      "showEasing": "swing",
      "hideEasing": "linear",
      "showMethod": "fadeIn",
      "hideMethod": "fadeOut"
       });  
});

【问题讨论】:

  • payload.data.Nick?

标签: javascript firebase firebase-cloud-messaging toastr


【解决方案1】:

这只是一个 JSON 对象,因此您可以使用 payload.data.Nickpayload.data.Room 访问数据属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-19
    • 2012-10-07
    • 2013-08-30
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多