这是我的代码。当我的应用程序被杀死并重新启动推送通知时,它应该正确地重定向,但是它实际上从来没有进入pushNotification.notificationCallback = function(event)
,因此不知道为什么。
function initPushWoosh() {
try {
checkNetworkConnection();
if(!window.plugins) {
wodifyRedirect('unknown-' + device.token);
return;
}
var pushNotification = window.plugins.pushNotification;
pushNotification.notificationCallback = function(event) {
var notificationId = 0;
if(event.u && event.u.custom) {
notificationId = event.u.custom;
} else if(event.u) {
notificationId = JSON.parse(event.u).custom;
} else if(event.custom && event.custom.custom) {
notificationId = event.custom.custom;
} else if(event.custom) {
notificationId = JSON.parse(event.custom).custom;
}
if(event.onStart && notificationId != 0) {
navigateToNotifications(notificationId, device.uuid);
}
};
实际上定义了自己的通知回调:
PushNotification.prototype.notificationCallback = function(notification) {
var ev = document.createEvent('HTMLEvents');
ev.notification = notification;
ev.initEvent('push-notification', true, true, arguments);
document.dispatchEvent(ev);
};
这可以通过:
来处理document.addEventListener('push-notification', function(event) {
请参阅此处的PushWoosh示例应用程序:
https://github.com/shaders/phonegap-3-sample-app/tree/master/master/www