1
沒有錯誤發生,但是當我運行程序時它崩潰了。無法從iOS發送多個參數到雲代碼
應用程序代碼
@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但它並沒有奏效。
它會崩潰哪條線在哪裏? – nick9999 2015-02-24 20:39:48
它解決了我使用 var user = request.user; var date = request.params.date; 謝謝 – 2015-02-25 06:28:00