1

I am sending push notification from iOS and Android both by calling a cloud function, and in each device I am getting 5 times a single push notification. I am using parse database hosted on back4app.

Cloud code is given below:

Parse.Cloud.define("push", function (request, response) {
    var query = new Parse.Query(Parse.Installation);
    var userID = request.params.user; 
    var message = request.params.message; 
    var notificationType = request.params.notificationType;
    var user = new Parse.User();
    user.id = userID;    
    query.equalTo('user', user);
    query.equalTo("allowPush", true);
    Parse.Push.send({
        where: query, 
        data: {
                alert: message,
                sound: 'default',
                "type": notificationType
              }
        },  { useMasterKey: true });
});
Umar Ata
  • 4,170
  • 3
  • 23
  • 35

1 Answers1

3

Try to call reponse.success and response.error functions in the end of your cloud code function. Since your client code is not receiving the feedback if the call worked or not it is probably attempting to send again.

Parse.Cloud.define("push", function (request, response) {
    var query = new Parse.Query(Parse.Installation);
    var userID = request.params.user; 
    var message = request.params.message; 
    var notificationType = request.params.notificationType;
    var user = new Parse.User();
    user.id = userID;    
    query.equalTo('user', user);
    query.equalTo("allowPush", true);
    Parse.Push.send({
       where: query, 
       data: {
            alert: message,
            sound: 'default',
            "type": notificationType
       }
    },
    {
       success: function () { response.success(); },
       error: function(err) { response.error(err); },
       useMasterKey: true
    });
});
Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11