2015-02-24 53 views
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但它並沒有奏效。

+0

它會崩潰哪條線在哪裏? – nick9999 2015-02-24 20:39:48

+0

它解決了我使用 var user = request.user; var date = request.params.date; 謝謝 – 2015-02-25 06:28:00

回答

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"); 
          } 
          }); 
       }); 
+0

謝謝你的工作 var user = request.user; var date = request.params.date; – 2015-02-25 06:26:35