简体   繁体   中英

Events and callbacks firing incorrectly in pushwoosh push notifications

I'm using the plugin's registerDevice and unregisterDevice methods and looking at my app's control panel in pushwoosh. My app's preference defaults to accepting push notifications, so I register, that works and my subscriber count increments in pushwoosh control panel. It also fires a push-notification event where the event has the notification property as the guide shows, but it's set to null . This is confusing as I have not yet sent any push notifications from the control panel.

I then set my push preference to false and unregister the the device. It works because my subscriber count decrements in the control panel, but the fail callback is the one that fires, and the only argument it gets is the same push token string that the register success callback got. If I unregister again after that, still only the fail callback fires but this time the only argument is the empty string.

Am I doing something wrong with handling responses from the plugin?

The code I'm testing with:

(function() {
    $document.on('push-notification', function(evt) {
        var n = evt.originalEvent.notification;
        console.log(n);
    });

    var pushPrefApply = function() {
        app.pushPref(function(pushPref) {
            console.log('pushPref', pushPref);
            if (!pushPref) {
                window.plugins.pushNotification.unregisterDevice(
                    function() {
                        console.log('unreg ok', arguments);
                    },
                    function() {
                        console.log('unreg fail', arguments);
                    }
                );
                return;
            }
            window.plugins.pushNotification.registerDevice(
                {
                    projectid: '123456789012',
                    appid : 'F0000-BAAAA'
                },
                function(pushToken) {
                    console.log('reg ok', arguments);
                },
                function(status) {
                    console.log('reg fail', arguments);
                }
            );
        });
    };

    //code for changing/initiating push preference goes here
})();

$document is not a typo, it's defined already. app.pushPref is the preference setting/fetching function. window.plugins.pushNotification.onDeviceReady has been done elsewhere on deviceready .

I'm hoping the pushwoosh devs will shed some light on this.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM