本文转自:https://github.com/phonegap-build/PushPlugin/issues/213
问:Hello, I would like to know how can I open a specific page in the application by clicking on the notification
答:
Here you have this piece of code (from my app) outside "devide ready" to recieve the push including the extra value. This works for me fine in ios and android (I can't tested it in wp8 becuse is not merged into build service until now)
//************************************ OUTSIDE DEVICE READY
// handle APNS notifications for iOS
function onNotificationAPN(e) {
// storage the e.id value (the extra value sent in push notification)
window.localStorage.setItem("push_que", e.id);
var push_que=e.id;
// if the push notification is coming inline
if (e.foreground=="1")
{
// storage the e.numero value (the extra value sent in push notification)
window.localStorage.setItem("push_que", e.id);
var push_que=e.id;
/// some code here to open a message if a new push is recieved inline
;}
if ( event.alert )
{
navigator.notification.alert(event.alert);
}
if ( event.sound )
{
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge )
{
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
}
// handle GCM notifications for Android
function onNotificationGCM(e) {
switch( e.event )
{
if (e.foreground)
{
// if the push is recieved inline
// storage the value of playoad.id, the extra value sent by push
window.localStorage.setItem("push_que", e.payload.id);
var push_que=e.payload.id;
}
else
{
// otherwise we were launched because the user touched a notification in the notification tray
if (e.coldstart)
{
// storage the value of playoad.numero, the extra value sent by push
window.localStorage.setItem("push_que", e.payload.id);
}
else
{
// storage the value of playoad.numero, the extra value sent by push
window.localStorage.setItem("push_que", e.payload.id);
}
}
break;
case 'error':
break;
default:
break;
}
}
//********************************** END OUTSIDE DEVICE READY