解析推送通知云代码错误?

时间:2016-07-30 23:33:33

标签: ios swift parse-platform cloud-code

更新:由于Parse-Server 2.2.17存在错误,我收到此错误。我通过回到2.2.16来修复它。

有谁知道我收到此错误的原因?这是我的云代码:

`Parse.Cloud.define(“Messages”,function(request,response){

var pushQuery = new Parse.Query(Parse.Installation);

Parse.Push.send({
    where: pushQuery,
    data: {
    alert: "New Event Added",
    sound: "default"
    }
    },{
    success: function(){
        console.log("Push Sent!")
    },
    error: function (error) {
        console.log(error)
    },
  useMasterKey: true

}); });`

以下是我收到的错误:enter image description here

然后这就是我调用代码的方式:`PFCloud.callFunctionInBackground(“Messages”,withParameters:nil){(object,error)in

            if error == nil {

                print("Success!")

            } else {

                print(error)
            }
        }

index.js:enter image description here `

2 个答案:

答案 0 :(得分:1)

您能否请尝试以下代码:

var query = new Parse.Query(Parse.Installation);
// query condition (where equal to .. etc.)

var payload = {
    alert: "New Event Added",
    sound: "default" 
};





Parse.Push.send({
    where: query, // Set our Installation query
    data: payload
}, {
        success: function () {

        },
        error: function (error) {
            // Handle error
        }
    });

请注意我删除了 useMasterKey ,如果你想添加useMasterKey,你需要将它插入封闭内容,但对我而言,没有useMasterKey

useMasterKeyVersion应如下所示:

Parse.Push.send({
    where: query, // Set our Installation query
    data: payload
},
{
   useMasterKey: true
},
{
    success: function () {

    },
    error: function (error) {
        // Handle error
    }
});

承诺版本(根据最佳实践):

Parse.Push.send({where: query,data: payload})
.then(function(){
    // success
},function(error){
    // error .. 
});

<强>更新

通过查看index.js文件,您似乎没有将facebook oauth添加到您的3方身份验证登录中。 所以你需要添加以下内容:

oauth: {
   facebook: {
     appIds: "FACEBOOK APP ID"
   }
}
emailAdapter 配置下方

以及“FACEBOOK APP ID”中,将您在Facebook开发者中创建的应用ID添加到

答案 1 :(得分:0)

在main.js中的

放了这段代码

// SEND PUSH NOTIFICATION
Parse.Cloud.define("push", function(request, response) {

  var user = request.user;
  var params = request.params;
  var someKey = params.someKey
  var data = params.data

  var recipientUser = new Parse.User();
  recipientUser.id = someKey;

  var pushQuery = new Parse.Query(Parse.Installation);
  pushQuery.equalTo("userID", someKey);


  Parse.Push.send({
    where: pushQuery, // Set our Installation query
    data: data
  }, { success: function() {
      console.log("#### PUSH OK");
  }, error: function(error) {
      console.log("#### PUSH ERROR" + error.message);
  }, useMasterKey: true});

  response.success('success');
});



// SEND PUSH NOTIFICATION FOR ANDROID
Parse.Cloud.define("pushAndroid", function(request, response) {

  var user = request.user;
  var params = request.params;
  var someKey = params.someKey
  var data = params.data

  var recipientUser = new Parse.User();
  recipientUser.id = someKey;

  var pushQuery = new Parse.Query(Parse.Installation);
  pushQuery.equalTo("userID", someKey);


  Parse.Push.send({
    where: pushQuery, // Set our Installation query
    data: {
       alert: data
    }
}, { success: function() {
      console.log("#### PUSH OK");
  }, error: function(error) {
      console.log("#### PUSH ERROR" + error.message);
  }, useMasterKey: true});

  response.success('success');
});
xcode项目中的

就像发送推送通知一样

     // Send Push notification
        let pushStr = "@\(PFUser.current()![USER_USERNAME]!) | \n\(self.lastMessageStr)"


        let data = [ "badge" : "Increment",
                     "alert" : pushStr,
                     "sound" : "bingbong.aiff",

            ] as [String : Any]
        let request = [
            "someKey" : self.userObj.objectId!,
            "data" : data

            ] as [String : Any]
        PFCloud.callFunction(inBackground: "push", withParameters: request as [String : Any], block: { (results, error) in
            if error == nil {
                print ("\nPUSH SENT TO: \(self.userObj[USER_USERNAME]!)\nMESSAGE: \(pushStr)\n")
            } else {
                print ("\(error!.localizedDescription)")
            }
        })