Search code examples
javascriptiosswiftparse-serverparse-cloud-code

Parse Server Cloud Code set notifications badge to specific number


I am using cloud code on parse server to send push notifications to specific users on the app. Currently the badge is set to increment for each notification the user receives, which isn't bad, however I find it unattractive to see high numbers in the badge icon. I was wondering if instead of incrementing with each notification I can just set the badge number to be 1 so even if the user has 5 new notifications it will always say 1 in the corner.

Here is what my current javascript cloud code looks like

  Parse.Cloud.define("mentions", function(request,response){
 
  var message = request.params.message;
  var pushQuery = new Parse.Query(Parse.Installation);
  pushQuery.equalTo("user",request.params.User);	
	
  Parse.Push.send({
    where: pushQuery,
    data : { 
      alert: message,
      badge: "increment",
    }
    }, {
    success: function(result) {
    console.log(JSON.stringify(result));
    response.success(result);
    },
    error: function(error) {
    console.error(JSON.stringify(error));
    response.error(error.message)
    },
  useMasterKey: true

  });

});


Solution

  • badge: 1, check the guide here:

    http://docs.parseplatform.org/rest/guide/#sending-options

    Looks like that option is iOS only, though, so you won't be able to do this for Android.

    The value should be a number, unless you are specifying "Increment" to add one to the current badge number.