【问题标题】:How to send Push Notifications with Parse.com Cloudcode如何使用 Parse.com Cloudcode 发送推送通知
【发布时间】:2014-09-10 16:08:19
【问题描述】:

我想在 Parse.com 上使用 Cloudcode 发送推送通知。

推送通知应该发送到订阅特定频道并触发服务的所有安卓设备。

【问题讨论】:

    标签: javascript parse-platform parse-cloud-code


    【解决方案1】:

    您只需要一个安装查询以及随附的推送。例如:

    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.containedIn("user", userlist);
    Parse.Push.send({
      where: pushQuery, 
      data: {
         alert: "Your push message here!"
      }
    }, {
      success: function() {
        response.success("pushed");
      }, error: function(error) {
       reponse.error("didn't push");
      }
    });
    

    该安装查询可以是基于频道的查询,您可以为推送查询制定其他规范,文档中给出:

    Parse Docs

    【讨论】:

      【解决方案2】:

      您无需查询即可向频道发送推送。只需调用Parse.Push.send 并将通道数组添加到数据对象。

      Parse.Push.send({
              channels: [ "channel_name" ],
              data: {
                  alert: "Alert message"
              }
          }, {
              success: function () {
                  response.success("Push was sent");
              },
              error: function (error) {
                  response.error("Could not send push " + error)
              }
          });
      

      确保不要在频道名称中使用空格和大写字母。该频道不会添加到后端订阅的频道中。

      【讨论】:

      • 如果我想把这条消息发给所有人怎么办?我应该将channels 设置为“所有人”吗?
      【解决方案3】:

      1) 添加

      Parse.initialize("APPLICATION_ID", "JAVASCRIPT_KEY");
      

      2) 在 Parse.com 中启用 Java 脚本推送通知

      3) 下载Java脚本项目“parse-js-blank”

      4) 使用 Channel 创建安装对象

      5) 发送请求。

      Parse.Push.send({
                channels: [ "Giants","Vaquar" ],
                data: {
                  alert: "Vaquar Alert Message."
                }
              }, {
                success: function() {
                  // Push was successful
                },
                error: function(error) {
                  // Handle error
                  alert("(error"+eval(error));
                }
              });
      

      参考:https://parse.com/docs/js/guide#push-notifications

      【讨论】:

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