使用云代码解析查询会话 class
Query Session class with cloud code Parse
我正在尝试使用用户 ID 发送推送通知。我已经测试过使用 installationId 发送,查询 _Installation class,但我想查询用户指针的会话 class,然后转身查询安装 class。
我的问题出在查询会话class的限制上。我用createWithoutData()成功发现, and I know it is working because i can output that user. However, even after using the master key found here,结果总是空
向特定用户发送推送通知的一般做法是,您将在安装中存储指向用户的指针 class...例如,当用户注册时执行此操作
Swift
if let installation = PFInstallation.current() {
installation["user_id"] = PFUser.current()!
installation.saveInBackground()
}
云码
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'
};
我正在尝试使用用户 ID 发送推送通知。我已经测试过使用 installationId 发送,查询 _Installation class,但我想查询用户指针的会话 class,然后转身查询安装 class。
我的问题出在查询会话class的限制上。我用createWithoutData()成功发现
向特定用户发送推送通知的一般做法是,您将在安装中存储指向用户的指针 class...例如,当用户注册时执行此操作
Swift
if let installation = PFInstallation.current() {
installation["user_id"] = PFUser.current()!
installation.saveInBackground()
}
云码
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'
};