我在Parse.com上有一个云代码,在PFObject上搜索并在创建日期的基础上返回它,代码如下:
Parse.Cloud.define("getJournalEntry", function(request, response) {
var currDate = request.params.currDate;
var d1 = new Date(currDate + 1000 * 60 * 60 * 24 * 1); // gets 7 days ago
var query = new Parse.Query("JournalEntry");
query.greaterThan("createdAt",currDate);
query.lessThan("createdAt",d1);
query.find({
success: function(results) {
var entry = results[0];
response.success(entry);
},
error: function() {
response.error("no entry found");
}
});
});
我正在尝试从iOS应用程序调用此代码,如下所示
NSDate *dateOfMonth = .....;// some calculations
[PFCloud callFunctionInBackground:@"getJournalEntry"
withParameters:@{@"currDate": dateOfMonth}
block:^(PFObject *entry, NSError *error) {
if (!error) {
NSLog(entry[@"text"]);
}
else
{
NSLog(error.description);
}
}];
从控制台检查此代码时,如果我提供错误的日期,则会返回预期的回复,但在iOS中它总是崩溃并出现以下错误
2014-07-16 18:18:44.343 Emojo[2845:60b] -[NSNull objectForKeyedSubscript:]: unrecognized
selector sent to instance 0x27f3068
2014-07-16 18:18:44.345 Emojo[2845:60b] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSNull objectForKeyedSubscript:]: unrecognized selector
sent to instance 0x27f3068'
可能是什么问题?
即使发送正确的日期或错误的日期,我也会这样做。
答案 0 :(得分:3)
尝试这可能会有所帮助
<强>更新强>
NSDate *dateOfMonth = [NSDate date];
NSDateFormatter *dateformat = [[NSDateFormatter alloc]init];
[dateformat setDateFormat:@"dd-MM-YYYY"];
NSMutableDictionary *dateOfMonthDic = [[NSMutableDictionary alloc]init];
[dateOfMonthDic setValue: [dateformat stringFromDate:dateOfMonth ] forKey:@"currDate"];
[PFCloud callFunctionInBackground:@"getJournalEntry"
withParameters:dateOfMonthDic
block:^(PFObject *entry, NSError *error) {
if (!error) {
NSLog(entry[@"text"]);
}
else
{
NSLog(error.description);
}
}];
谢谢;干杯..