I have successfully implement the push notification using ( https://github.com/phonegap-build/PushPlugin ) in cordova.Everthing works correctly except that push notification is not showing when the app is running(ie foreground).Here is the code
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( e.foreground )
{
// if this flag is set, this notification happened while we were in the foreground.
//this is not working
if(e.foreground){
var myMedia = new Media("/assets/www/img/beep.mp3");
my_media.play();
}else{
// otherwise we were launched because the user touched a notification in the notification tray.
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (e.foreground) {
//when you are running the app, you get the alert
alert(e.payload.message);
}
else {
//do something for the case where user is not using the app.
if (e.coldstart)
console.log('--COLDSTART NOTIFICATION--' + '');
else
console.log('--BACKGROUND NOTIFICATION--' + '');
$window.location.href = ('#/bucket/notification');
}
break;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.