我试图在Parse中调用云代码函数,但是每当调用它时,我都会收到以下错误,但不知道为什么它无效:
2019-04-30T11:0 1:44.020Z-无效的函数:“ pushTenFTC”
云代码:
Parse.Cloud.define("pushTenFTC", async (request) => {
var query = new Parse.Query(Parse.Installation);
let userId = request.params.userId;
query.equalTo('userId', userId);
Parse.Push.send({
where: query,
data: {
alert: "Fitcoins Gifted!",
title: userId + " sent you 10 Fitcoins!"
}
}).then(function() {
// Push was successful
}, function(error) {
// Handle error
});
在Swift中调用
var params = [AnyHashable: Any]()
params["userId"] = feedElements[sender.tag].objectID
PFCloud.callFunction(inBackground: "pushTenFTC", withParameters: params) { (response, error) in
if let error = error {
//error handling
return
}
//Success
}
答案 0 :(得分:3)
似乎在函数末尾缺少});
,并且还需要masterKey
发送推送通知。
整个功能应如下所示...
Parse.Cloud.define("pushTenFTC", async (request) => {
var query = new Parse.Query(Parse.Installation);
let userId = request.params.userId;
query.equalTo('userId', userId);
Parse.Push.send({
where: query,
data: {
alert: "Fitcoins Gifted!",
title: userId + " sent you 10 Fitcoins!"
}
}, {useMasterKey: true}).then(function() {
// Push was successful
}, function(error) {
// Handle error
});
});