gpt4 book ai didi

ios - 无法将多个参数从 iOS 发送到 Cloud Code

转载 作者:行者123 更新时间:2023-11-29 10:32:52 24 4
gpt4 key购买 nike

没有发生错误,但是当我运行程序时它崩溃了。

应用代码

@property (nonatomic, strong) NSDate *CurrentDate;

- (void) GetCalUsed{
NSMutableDictionary *params = [NSMutableDictionary new];
PFUser *user = [PFUser currentUser];
CurrentDate = [NSDate date];
params[@"user"] = user.objectId;
params[@"date"] = CurrentDate;
[PFCloud callFunctionInBackground:@"CalUsed"
withParameters:params
block:^(NSNumber *CalUsed1, NSError *error) {
if (!error) {
NSLog(@"Calories : %@",CalUsed1);
CalUsed = CalUsed1;
NSLog(@"Selected Date : %@",CurrentDate);


}

}];

云代码

Parse.Cloud.define("CalUsed", function(request, response) {
var user = request.user;
var date = request.date;
var query = new Parse.Query("FoodLog");

query.equalTo("user",user);
query.equalTo("Date",date);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("Calories");
}
response.success(sum);
},
error: function() {
response.error("lookup failed");
}
});
});

我试过按照这个方法sending multiple parameters in "withParameters:" call但它不起作用。

最佳答案

你应该在请求之后和字典键之前有 .params:

Parse.Cloud.define("CalUsed", function(request, response) {
var user = request.params.user;
var date = request.params.date;
var query = new Parse.Query("FoodLog");

query.equalTo("user",user);
query.equalTo("Date",date);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("Calories");
}
response.success(sum);
},
error: function() {
response.error("lookup failed");
}
});
});

关于ios - 无法将多个参数从 iOS 发送到 Cloud Code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28705719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com