我的应用程序中有一个功能,其中一个用户填写表单并将其保存为解析。我希望将保存的对象发送给用户b(在保存的对象中有一个指向用户b的指针)。我为此做了一个afterSave函数,但是我遇到了错误。我仍然是javascript的新手,所以如果有人可以帮助我,我将非常感激。提前谢谢。
Parse.Cloud.define("sendDealToConfirm", function(request, response) {
var sender = request.user;
var recipientUserId = request.params.recipientId;
var task = request.params.task;
var price = request.params.price;
var address = request.params.address;
var time = request.params.time;
var taskP = request.params.taskP;
//send the push
var recipientUser = new Parse.User();
recipientUser.id = recipientUserId;
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("user", recipientUser);
Parse.Push.send({
where: pushQuery,
data: {
alert: "You have a new deal to confirm!",
task: task,
poster: sender,
price: price,
address: address,
time: time,
taskP: taskP
}
}).then(function(){
response.success("Deal was sent successfully.")
}, function(error){
response.error("Deal failed to send:" + error.message);
});
});
这是我的iOS代码
[PFCloud callFunctionInBackground:@"sendDealToConfirm"
withParameters: @{@"recipientId": self.doer, @"task": self.details[@"Task_Name"], @"price": self.dealPrice, @"address": self.dealAddress, @"time": self.dealTime, @"taskP": self.details[@"Task_Pointer"]}
block:^(NSString *success, NSError *error) {
if (!error){
NSLog(@"Push successful");
} else {
NSLog(@"Error in push %@", error);
}
}];
编辑以下是崩溃报告
***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'此处不允许使用PFObject。'
答案 0 :(得分:0)
您的云代码似乎很好,但以下NSDictionary
的其中一个对象可能是PFObject
吗?
@{@"recipientId": self.doer, @"task": self.details[@"Task_Name"], @"price": self.dealPrice, @"address": self.dealAddress, @"time": self.dealTime, @"taskP": self.details[@"Task_Pointer"]}
因为,afaik Parse不允许PFObject
中的Parse.Cloud.define
尝试将PFObject
s id
作为NSString
传递给参数,并在云代码中创建一个带有id的对象。