我正在尝试调用Parse CloudCode函数并接收响应的数组。不幸的是我的iOS应用崩溃了。它认为我没有正确匹配Parse的返回类型。不幸的是,我对力量的了解 - 我的意思是Java--是有限的。
iOS代码:
[PFCloud callFunctionInBackground:@"storyReadCount"
withParameters:@{}
block:^(NSArray *results, NSError *er)
{
if (er) {
NSLog(@"the error is %@", er);
}else{
if (results.count > 0) {
//iterate through results adding story objects to array
for (int lCounter = 0; lCounter < results.count; lCounter ++) {
PFObject *singleObject = [results objectAtIndex: lCounter];
RSSStory *singleStory = [[RSSStory alloc] init];
singleStory.link = [singleObject objectForKey: @"link"];
singleStory.readCount = [singleObject objectForKey: @"count"];
singleStory.loveCount = [singleObject objectForKey: @"heart"];
[array addObject: singleStory];
}
_totalStoryReadCount = array;
[[NSNotificationCenter defaultCenter] postNotificationName: @"PriorStoryCountLoaded" object: nil];
}
}
}
];
解析CloudCode:
//gets and returns array containing number of times each article has been read
Parse.Cloud.define("storyReadCount", function(request, response) {
var query = new Parse.Query("Story");
query.descending("createdAt");
query.exists("link");
query.limit (100);
query.find({
success: function(results) {
response.success(results);
},
error: function(error) {
response.error("Failed");
}
})
}
);
我发誓它正常工作了一天。我注释掉了(错误)else阻止验证没有逻辑错误,但崩溃发生在此之前。
崩溃错误消息似乎有所不同,但是有一些变体:__ NSDate UTF8String]:无法识别的选择器发送到实例。我偶尔也会在崩溃日志中看到_NSTaggedDate。
我也尝试过改变:
block:^(NSArray *results, NSError *er)
到
block:^(NSString *results, NSError *er)
和
block:^(PFObject *results, NSError *er)
为了好玩,我试过了:
block:^(NSDate *results, NSError *er)
答案 0 :(得分:0)
以下是如何使用promises从云查询返回结果...
Parse.Cloud.define("storyReadCount", function(request, response) {
var query = new Parse.Query("Story");
query.descending("createdAt");
query.exists("link");
query.limit (100);
query.find().then(function(results) {
response.success(results);
}, function(error) {
response.error(error);
});
});
答案 1 :(得分:0)
这就解决了我的问题:
到我的cloudCode查询添加:
query.include("UserID");