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

时间:2015-02-24 20:34:03

标签: ios iphone parse-platform cloud-code

不会发生错误,但是当我运行程序时它会崩溃。

应用代码

@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,但它不起作用。

1 个答案:

答案 0 :(得分:2)

请求之后和字典键之前应该有.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");
                          }
                          });
               });