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);
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.
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();
});
})
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).
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
@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.
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:
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?
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.