本文介绍了解析云代码无效函数被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

云代码:

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发送推送通知.

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

这篇关于解析云代码无效函数被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:12