简体   繁体   English

如何向特定用户发送解析推送通知

[英]How to send a Parse Push notification to a specific user

I'm trying to make a Cloud code to send a Push Notification to a specific user. 我正在尝试制作一个Cloud代码,以向特定用户发送推送通知。

The Parse user can have several installations. 解析用户可以有多个安装。

I want to send the notification only to the First created User. 我只想将通知发送给第一个创建的用户。 I'm writing this cloud code function, but it seems to send push notifications to all the installation files and not to the recent one. 我正在编写此云代码功能,但它似乎将推送通知发送到所有安装文件,而不是最新的。

var query = new Parse.Query(Parse.Installation);
    var fromUser = new Parse.User({id:request.params.userId});
    query.equalTo("user", fromUser);
    query.equalTo("channels", "main");
    query.descending("createdAt");
    query.first({
    success: function(installation)
    {

     var device = installation.get("deviceType")    
     if (device == "ios") {
                Parse.Push.send({
      where : query,
      data : {
      title : title,
      alert: alert,
      sound : "chime", 
      badge: "Increment",
          }

      }, { success: function() { 
      response.success("Success");
      }, error: function(err) { 
       response.error(err);
      }
});   

I have not done this in cloud code but in rest via python. 我没有在云代码中执行此操作,而是通过python进行了此操作。 You could query the users table to obtain first user then join to installations to obtain installation ID. 您可以查询用户表以获得第一个用户,然后加入安装以获得安装ID。 Then place installation ID='the id you got from your join' in the where clause. 然后将安装ID =“您从联接中获得的ID”放在where子句中。 Exact syntax is available in the docs. 确切的语法在文档中可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM