2014-01-17 114 views
1

这是我的代码。当我的应用程序被杀死并在推送通知中重新启动时,它应该正确重定向,但它实际上从未进入pushNotification.notificationCallback = function(event)不知道为什么。PushWoosh notificationCallback not firing

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); 
         } 
        }; 

回答

0

其实Pushwoosh定义了自己的通知回调:

document.addEventListener('push-notification', function(event) { 

见Pushwoosh示例应用程序在这里:

https://github.com/shaders/phonegap-3-sample-app/tree/master/www

PushNotification.prototype.notificationCallback = function(notification) { 
      var ev = document.createEvent('HTMLEvents'); 
      ev.notification = notification; 
      ev.initEvent('push-notification', true, true, arguments); 
      document.dispatchEvent(ev); 
    }; 

这可以通过处理