Search code examples
iosswiftparse-platformparse-cloud-code

Parse Push Notification Cloud Code Error?


UPDATE: I was getting this error because of a bug that Parse-Server 2.2.17 has. I fixed it by going back to 2.2.16.

Does anyone know why I am getting this error? Here is my cloud code:

`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

}); });`

Here is the error I am getting: enter image description here

And then this is how I am calling the code: `PFCloud.callFunctionInBackground("Messages", withParameters: nil) { (object, error) in

            if error == nil {

                print("Success!")

            } else {

                print(error)
            }
        }

index.js: enter image description here `


Solution

  • Can you please try the following code:

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

    Please notice that i remove the useMasterKey if you want to add useMasterKey you need to insert it inside closures but for me it's works without the useMasterKey

    the useMasterKeyVersion should look like the following:

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

    The promises version (according to best practices):

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

    Update

    by looking at your index.js file it looks like you didn't add the facebook oauth to your 3-party authentication logins. so you will need to add the following:

    oauth: {
       facebook: {
         appIds: "FACEBOOK APP ID"
       }
    }
    

    below your emailAdapter config and inside "FACEBOOK APP ID" put the app ID that you created in facebook developers