2016-10-01 71 views
0

我想发送推送通知使用用户的ID。我已经测试了使用installationId发送,查询_Installation类,但是我想查询用户指针的会话类,然后转过头来查询安装类。查询会议类与云代码解析

我的问题在于查询会话类的限制。我已经成功地使用了createWithoutData()发现here,我知道它正在工作,因为我可以输出该用户。但是,即使在使用找到的主密钥here之后,结果始终为空。

回答

0

发送推送通知到特定的用户一般的做法是,你将存储指向用户在安装类...例如,当用户注册为此

斯威夫特

if let installation = PFInstallation.current() { 
    installation["user_id"] = PFUser.current()! 
    installation.saveInBackground() 
} 

Cloudcode

 var pushQuery = new Parse.Query(Parse.Installation); 
     pushQuery.equalTo('user_id', tarUser); 
     pushQuery.exists("deviceToken"); 
     pushQuery.limit(1); // in case there are more Installation with the user ID, use only the latest 
     pushQuery.descending("createdAt"); 
     Parse.Push.send({ 
     where: pushQuery, // Set our Installation query 
     data: { 
      alert: "Some push text" 
     } 
     }, { 
     success: function() { 
     // Push was successful 
     response.success(); 

     }, 
     error: function(error) { 
     console.error("Got an error " + error.code + " : " + error); 
     response.error(error); 
     }, 
     useMasterKey: true 
    }); 

如果我没记错的话要查询在云代码指针与指针结构,这样

var tarUser = { 
    __type: 'Pointer', 
    className: '_User', 
    objectId: 'insertObjectIDHere' 
}; 
+0

谢谢你,我将标志着你的答案是正确的供日后参考,但我偏不这样做,因为我想单独设备日志中,这意味着在注销另一个设备时需要扩展代码。 – Jacolack

+0

单一设备登录甚至意味着什么? –

+0

如果您熟悉snapchat,如果您登录到其他设备,则会为该用户删除所有其他会话。 – Jacolack