Backendless Support
 
Waiting for user's response

Sending Silent Push Notifications from JS Server Code

Hi,

I am having trouble sending silent push notifications. My intention is that in the iOS Notification Center, the notification does not show up by default, but is first handled by the app, and based on the payload, the app decides how to handle it.

I am on backendless 3, JS server code. This is what I came up with so far:

const channel = "default";

const message = "test"; // --- > I MUST SET THIS, otherwise "Error: MEssage property can't be null"

const publishOptions = new PublishOptions({

headers: {

// "ios-alert": null, // ---> my attempt to HIDE the alert

a: "a",

b: 2,

c: false // custom fields

}

});

const deliverOptions = new DeliveryOptions({

pushPolicy: 'ONLY'

});

return Backendless.Messaging.publish(channel, message, publishOptions, deliverOptions);

Leave a Comment

Comments (5)

photo
1

Hello Gal,

Could you please clarify the problem?

To send silent notifications please add this header: "content-avaliable" : 1 to awake your app in background.

Also you should omit the "ios-sound" header instead of assigning null value to it.

Regards, Olga

photo
1

Hi Olga,

The problem is that I want to send silent push notifications, but instead they show up on the iOS device's notification center (They are not silent).

const channel = "default";

const message = "1";

const publishOptions = new PublishOptions({

headers: { "content-available": 1,

a: 1,

b: 'b',

c: false

}

});

const deliverOptions = new DeliveryOptions({

pushPolicy: 'ONLY'

});

return Backendless.Messaging.publish(channel, message, publishOptions, deliverOptions);

When I use the code above in the JS server code to send a push notification, it shows up in the device's Notification Center with the title "1", taken from my message var. I only passed it in because I had to, I tried passing in both null and empty string instead and both resulted in an "Error: Message property can't be null" error being thrown.

With regards to content-available, i tried that as well, as you can see above, with 1, 0, true and false, just to be sure - in all cases the notification is still not silent.

photo
1

Hi!

Please try these headers:

  1. {"ios-alert":"","ios-badge":0, "ios-sound":"", "content-avaliable":1}

Regards, Olga

photo
1

Thanks. That didn't work either, as far as I can tell, no push notification comes through (at all, not silent nor regular)

photo
photo
1

Hello!

I've checked this issue once more. That should work fine:

Headers:

  1. "ios-content-available":1, "ios-alert":""

And then you can handle notification in didReceiveRemoteNotification method in AppDelegate

Regards, Olga