Ionic Push payload options (e.g. sound, badge) not working [solved]

I’ve hit a small snag with Ionic Push—even though pluginConfig specifies badge and sound as true, I don’t get a badge or sound when I receive the push on my device. I checked my Settings to ensure notifications are enabled for my app, and I also made sure my sound is turned on for my device.

Here’s my code:


angular.module('starter', ['ionic','ionic.service.core', 'starter.controllers', 'starter.services', 'ionic.service.push'])
.run(function($ionicPlatform, $ionicPush, $state) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
    $ionicPush.init({
      "debug": true,
      "onNotification": function(notification) {
        console.log(notification.text);
        $state.go('tab.chat-detail', {chatId: '1'});
      },
      "onRegister": function(data) {
        alert(data.token);
      },
      "pluginConfig": {
        "ios": {
          badge: "true",
          sound: "true"
        }
      }
    });
    $ionicPush.register();
  });
})

Here’s an example curl request:

curl -u my-private-key: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: my-app-id" 
https://push.ionic.io/api/v1/push -d '{"tokens": ["my-device-token"],"production": false, "notification":{ "alert":"Hi this is a 
push notif", "title": "Push title", "android": {"payload": {"sound": "true","badge": "1","content-available": "1"}}, "ios": 
{"payload": {"sound": "true","badge": "1","content-available": "1"}}}}'

Should be noted that with this particular request I was testing adding content-available to trigger the push behavior from the background, although I’m not sure if this option belongs in the payload or something different as the phonegap-plugin-push specifies that it’s part of the “aps” object. Either way, this setting should not be required to get badges and sound to work if the device is active/not asleep (I believe, anyway).

I notice in the doc for Push Usage that in onNotification there is a payload var, which is logged. However, in an iOS app, I wouldn’t log the payload. Do I need to do anything with this payload var to make it trigger on the device? I can’t imagine why this would be necessary, but just want to cover my bases.

Code example from Push Usage:

var push = new Ionic.Push({
  "debug": true,
  "onNotification": function(notification) {
    var payload = notification.payload;
    console.log(notification, payload);
  },
  "onRegister": function(data) {
    console.log(data.token);
  }
});

Does anybody have any thoughts on how to get badges and sound to work?

I finally got help on the gitter.im support channel.

Turns out my curl request was poorly formatted with badge and sound specified inside the payload. Turns out that they need to go as a child of “ios” rather than inside the payload. Here’s the ill-formatted request that I used previously:

curl -u my-private-key: -H “Content-Type: application/json” -H “X-Ionic-Application-Id: my-app-id” https://push.ionic.io/api/v1/push -d ‘{“tokens”: [“my”,“device”,“tokens”],“production”: false, “notification”:{ “alert”:“I’m a push”, “title”: “Hello world”, “android”: {“payload”: {“badge”: 4,“sound”: “default”}}, “ios”: {“payload”: {“badge”: 4,“sound”: “default”}}}}’

And here is the correctly formatted curl request that results in badge and sound working properly:

curl -u abfc6bf427fe53c4419685ec824cd34c59e2dba7734e1158: -H "Co https://push.ionic.io/api/v1/push -d ‘{“tokens”:[“d59764af2f9c36bd4d6252c0f80a1553a4d18ce51fefd83bbf32fb8468d38de8”],“notification”:{“alert”:“Hello World oh man!”,“ios”:{“badge”:1,“sound”:“default”}}}’

So, there we go…ha.