Search code examples
javascriptioscordovapush-notificationpushwoosh

PushWoosh notificationCallback not firing


here is my code. When my app is killed it and restarted on a push notification it should redirect properly however it never actually goes into the pushNotification.notificationCallback = function(event) Have no clue as to why.

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

Solution

  • Actually Pushwoosh defines its own notification callback:

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

    this could be handled by:

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

    See Pushwoosh sample app here:

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