Hello,
I am creating an app with ionic and ngCordova. The app shell receive push notifications.
I have adopted an example from ngCordova.
http://ngcordova.com/docs/plugins/pushNotifications/
My .run method looks like this:
.run(function ($ionicPlatform, $rootScope, User, $cordovaDialogs, $cordovaVibration, $cordovaPush) {
$ionicPlatform.ready(function () {
var androidConfig = {
"senderID": "xxx",
};
$cordovaPush.register(androidConfig).then(function(result) {
// Success
}, function(err) {
// Error
})
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
switch(notification.event) {
case 'registered':
if (notification.regid.length > 0 ) {
console.debug('registration ID');
console.debug(notification.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
});
});
})
I send push notifications with the following script:
The messages arrive, as far so good.
But I can’t manage to play a sound/tone. According to GCM documentation, this should work with the parameter sound and the value default.
My GCM request looks like this:
$apiKey = "YOUR GOOGLE API SERVER KEY";
$devices = array('YOUR REGISTERED DEVICE ID');
$message = "The message to send";
$gcpm = new GCMPushMessage($apiKey);
$gcpm->setDevices($devices);
$response = $gcpm->send($message, array(‘title’ => ‘Test title’, ‘sound’ => ‘default’));
Has someone an idea why the sound is not played?
Thank you in advance!