Parse Cloud Code Push to Android Not Working

133 views Asked by At

My cloud code looks like this. It sends just fine to iOS, but when sent to an Android device, instead of a message, it gets a whole lot of JS code for the payload.:

Parse.Cloud.define("userPraying", function(request, response) {
    var prayersObjectID = request.params.prayersObjectID;
    var whoPrayed = request.params.theirName;
      var recipientUserId = request.params.recipientId;
    var newRecipientUserId = recipientUserId.replace('User_', '');


  var pushQuery = new Parse.Query(Parse.Installation);
  pushQuery.equalTo("usersObjectId", newRecipientUserId);

    Parse.Push.send({
    where: pushQuery,
    data: {
      alert: {
      title: "Prayers Lifted!",
     body: whoPrayed + " just prayed for you.",
     "loc-args": prayersObjectID,
      },



      category : "TAGGED_CATEGORY",
 sound: "default.caf"
    }
  }).then(function() {
      response.success("Push was sent successfully.")
  }, function(error) {
      response.error("Push failed to send with error: " + error.message);
  });

});

When it is sent to an Android user, they get all of the Javascript code, instead of just the body of the message. How can this be fixed?

1

There are 1 answers

2
cYrixmorten On BEST ANSWER

The data literal:

data: {
  alert: {
  title: "Prayers Lifted!",
  body: whoPrayed + " just prayed for you.",
  "loc-args": prayersObjectID,
  },



  category : "TAGGED_CATEGORY",
  sound: "default.caf"
}

Looks invalid from what I can tell in the documentation. https://parse.com/docs/js/guide#push-notifications-customizing-your-notifications

What happens if you do:

data: {
  alert: "Some alert",
  title: "Prayers Lifted!",
  body: whoPrayed + " just prayed for you.",
  loc-args: prayersObjectID,
  category : "TAGGED_CATEGORY",
  sound: "default.caf"
}