Parse Cloud Code Invalid Function being called

2019-08-04 01:15发布

I'm trying to call a cloud code function in Parse but whenever it gets called I get the following error, but have no idea why it is invalid:

2019-04-30T11:0 1:44.020Z - Invalid function: "pushTenFTC"

Cloud Code:

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
});

Called in 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
}

1条回答
相关推荐>>
2楼-- · 2019-08-04 01:45

It seems you are missing }); at the end of the function and your masterKey is also required to send push notifications.

The whole function should look like this...

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
  });
});
查看更多
登录 后发表回答