解析正在调用的云代码无效函数

Parse Cloud Code Invalid Function being called

我试图在 Parse 中调用云代码函数,但每当它被调用时,我都会收到以下错误,但不知道为什么它无效:

2019-04-30T11:0 1:44.020Z - Invalid function: "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
}

您似乎在函数末尾缺少 }); 并且还需要您的 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
  });
});