【问题标题】:Send custom data pushPlugin cordova php发送自定义数据 pushPlugin cordova php
【发布时间】:2015-10-06 13:21:29
【问题描述】:

这是在通知中发送消息和数据的代码。

$fields = array(
        'registration_ids' => $this->devices,
        'data'             => array(
                "message"      => $message,
                "msgcnt"       => "8",
                "collapse_key" => "dffbb")
        );

我面临的问题是我无法发送除msgcntcollapse_key 之外的任何其他内容。

警报给出未定义的例子

$fields = array(
        'registration_ids' => $this->devices,
        'data'             => array(
                "message"      => $message,
                "msgcnt"       => "8",
                "collapse_key" => "dffbb",
                "test_field"   => "test")
        );

【问题讨论】:

  • 我改进了格式;但是在例如之后仍然没有解释......请解释一下undefined。什么是未定义的?

标签: php cordova phonegap-plugins cordova-plugins phonegap-pushplugin


【解决方案1】:

您可以使用这样的自定义数据创建另一个数组:

$fields = array(
                'registration_ids'  => $this->devices,
                'data'              => array("message" => array("text_message" => $message, "test_field" => "test"),
                                            "msgcnt"=>"8",
                                            "collapse_key"=>"dffbb",
                                              )
            );

【讨论】:

    【解决方案2】:

    我知道了,返回的数据进入另一个名为 payload 的数组索引,所以如果你想在 javascript 中访问它,你可以试试。

    alert(e.payload.test_field);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多