Ionic push: no sound

I have Ionic push notifications working perfectly for Android and almost perfectly for iOS - with the exception that no sound is produced on the arrival of a notification.

My code is as follows:

    var push = new Ionic.Push({
        "debug": false,
        "onNotification": function (notification) {
            var payload = notification.payload;
            console.log("on notification: " + notification, payload);
        },
        "onRegister": function (data) {
            console.log("on register: " + data.token);
        },
        "pluginConfig": {
            "ios": {
                "alert": true,
                "sound": true,
                "badge": true
            }
        }
    });
    
    var user = Ionic.User.current();
    var callback = function (pushToken) {
        console.log('Registered token:', pushToken.token);
        user.addPushToken(pushToken);

        if (!user.id) {
            user.id = Ionic.User.anonymousId();
        }

        var success = function (response) {
            console.log('user was saved');
        };

        var failure = function (error) {
            console.log('user was NOT saved' + error);
        };

        user.save().then(success, failure);
    }

    push.register(callback);

Currently using:
iPad 2,
iOS: 8.4.1,
Ionic: 1.1.0,
Ionic CLI: 1.7.7,
phonegap-plugin-push: 1.2.3,
Cordova: 5.3.3,

If anyone has any ideas as to why this might be that’d be great :slight_smile:

1 Like

hi there… i get error uncaught reference error at the
"var push = new Ionic.Push" may i know how can i solve this issue?

Had exactly the same problem. Just be sure to add a “sound” property in the PN description you send from your server. Using “sound”:“ping.aiff” was all I had to do. Seems iOS has a file by this name, so I did not have to embed anything in my project.

Please refer to http://docs.ionic.io/docs/push-sending-push

1 Like

Hi, I made another post a while back which may help you:

Thanks for that, I’ve seen a few sources adding sound this way.

I am explicitly using the ionic dashboard to send my push notifications and was wondering if it’s at all possible to get iOS sound this way?

Sorry, no idea about that. Maybe someone from the Ionic camp can help?

@RWilliams did you ever figure this out?

I’m having the same problem where I want to send push notifications from the ionic.io dashboard and trigger a badge and sound when the push arrives. My pushes work from the dashboard, but the pluginConfig doesn’t seem to be acknowledged. I also checked my notification settings for my app and ensured everything is turned on and that my sound on my device is turned on.

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.chats');
        alert(notification.text);
      },
      "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).

Hi @stewartmccoy,

Sorry for the delayed response. I’m afraid I still haven’t figured this out and frankly, I’ve given up on the issue. I have recently completed my app and even using when using production pushes - there’s no sound. I have no idea, I think it may be a problem with the dashboard that’s out of our hands :confused:

@RWilliams thanks for getting back to me. Bummed to hear you didn’t figure it out. I wrote Ionic Support, but I’m still waiting to hear back on the issue. Since the Ionic docs are a bit lacking, I’m trying to do more research on the phonegap-push-plugin and see if I can uncover something in a writeup about that. I’ll followup if I find anything helpful.

1 Like

I hired a senior developer to pair with me and we came to the conclusion that there might be an error in the framework: https://github.com/driftyco/ionic-platform-web-client/issues/61

Waiting to hear back from the Ionic team. I’ll follow up again when I get a reply to the issue.

Hey @RWilliams,

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.

Hi, where is the location of the sound file. I put it in platform/android/res/raw folder as pointer in here but still get the default sound

Sorry, I was only using the default sound, so I don’t know.

I am using the correct format that @RWilliams mentioned. Still i am having the issue on ios. I haven’t tested on android yet. Do anyone found other reason than not proper request?

Here’s my request body :

{
"tokens":["83b7a063b0bcb85478d2b4ad8dfac5a619076e37204e95d8b90052d61fc93e55"],
"profile":"dev",
"notification": {
    "title": "Hi",
    "message": "Hello world!",
    "android": {
      "title": "Hey",
      "message": "Hello Android!",
       "content_available": 1,
       "soundname": "ringtone"
    },
    "ios": {
      "title": "Howdy",
      "message": "Hello iOS!",
       "content_available": 1,
       "sound":"default",
       "badge": 1
    }
  }
}

Interesting thing i noticed that in settings when i got to notification and choose my app there is no option of turning off/on sound even i am setting sound true.

var push = new Ionic.Push({
                "debug": true,
                ios: {
                  alert: true,
                  badge: true,
                  sound: true
                },
                onNotification: notify
              });

Hey guys. I’ve got sound working in iOS and put the sound file in the www folder. Make sure it is a “.caf” file (See the Apple docs). Also, if I want it to play notify.caf, I send just “notify” in my request.