2014-09-10 87 views

回答

4

你不需要查询来发送推送到频道。只需拨打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) 
     } 
    }); 

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

+1

如果我想将这个消息发送给大家? 我应该将'channels'设置为“Everyone”吗? – 2015-12-07 13:54:44

+0

您的代码有错误。 – zygimantus 2015-12-17 20:49:40

4

所有你需要的是一个安装查询,以及随附的推送。例如:

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

1

1)添加

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

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

3)下载Java脚本的项目 “解析JS-空白”

4)创建安装通道对象

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

相关问题