Javascript 从iOS应用程序调用云函数
我开发了云函数来计算最后一天的投票数Javascript 从iOS应用程序调用云函数,javascript,ios,swift,parse-platform,Javascript,Ios,Swift,Parse Platform,我开发了云函数来计算最后一天的投票数 // Use Parse.Cloud.define to define as many cloud functions as you want. // For example: Parse.Cloud.define("confidenceRating", function(request, response) { // To define vars yesterday and today var today = new Date();
// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:
Parse.Cloud.define("confidenceRating", function(request, response) {
// To define vars yesterday and today
var today = new Date();
var yesterday = today.setDate(today.getDate() - 1);
// "score" is the table's name
var query = new Parse.Query("score");
// filter the query, 2 filters to be applied
query.greaterThanOrEqualTo("createdAt", yesterday);
query.lessThan("createdAt", today);
// perfom the action
query.find({
success: function(results) {
var votes = results.length;
response.success(votes);
},
error: function() {
response.error("something went wrong");
}
});
});
我成功地部署了代码。但是如何开发SWIFT代码来调用函数呢?不幸的是,Parse.com上没有任何用于此目的的Swift示例。请帮帮我
Upd。1.我正在使用@rickerbh建议的代码
PFCloud.callFunctionInBackground("confidenceRating", withParameters: nil) { results, error in
if error != nil {
// Your error handling here
} else {
// Deal with your results (votes in your case) here.
}
}
但我发现了错误
2014-12-12 12:19:52.399 Rating[4082:166266] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]' *** First throw call stack: ( 0 CoreFoundation 0x012d3946 __exceptionPreprocess + 182
下面是一些调用云代码函数的swift代码
let parameters = ["": ""]
PFCloud.callFunctionInBackground("confidenceRating", withParameters: parameters) { results, error in
if error != nil {
// Your error handling here
} else {
// Deal with your results (votes in your case) here.
}
}
这会使编译器@Maga崩溃,可能会传入一个空字典作为参数。您的编译器发出的错误消息是什么?它不会使我的编译器崩溃…2014-12-12 12:19:52.399评级[4082:166266]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“***-[\u NSPlaceholderDictionary initWithObjects:forKeys:count::尝试从对象[1]插入nil对象”'***第一次抛出调用堆栈:0 CoreFoundation 0x012d3946\uu异常预处理+182@Maga这看起来不像是编译器崩溃。看起来像是运行时崩溃。你能用你实现的调用函数的代码更新你的问题吗?@Maga啊,看起来你肯定需要传入一些参数。检查更新的代码块。