Cordova PushPlugin onNotificationAPN(e) 回调不起作用或未定义

Cordova PushPlugin onNotificationAPN(e) callback not working or defined

我正在使用 Cordova/PhoneGap 插件 PushPlugin,我已经将它设置得很好并且可以正常工作,包括使用实时设备在我的本地服务器上测试 .php 和 .pem 文件(iPhone 5). IOS 8. 有几个问题,最主要的是 index.html 中对这个函数的调用:

            function onNotificationAPN(event) {
    console.log(event);
        if (event.alert) {
             $("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>');
             // showing an alert also requires the org.apache.cordova.dialogs plugin
             navigator.notification.alert(event.alert);
        }

        if (event.sound) {
            // playing a sound also requires the org.apache.cordova.media plugin
            var snd = new Media(event.sound);
            snd.play();
        }

        if (event.badge) {
            pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge);
        }
    }

事件的控制台输出是:

{"event":"message","payload":{"aps":{"alert":"My first push notification!","sound": "default"}},"foreground":真}

当应用程序在前台时,onNotificationAPN(event) 函数不会触发。 "event" 似乎以 JSON 格式返回或转换为 JSON 格式。

IOS注册行是:

pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});

如何修改代码以解码 JSON 格式并在应用程序位于前台时显示警报、播放声音、设置徽章。还必须有一些关于回调可以采用的格式和各种选项的文档。否则,似乎在工作。

经过一番尝试,我猜回调 "event" 实际上已经是一个 JSON 对象:

        console.log(e.event);
        console.log(e.payload.aps.alert);
        console.log(e.payload.aps.sound);
        console.log(e.foreground);

打印消息,我的第一个推送通知!,日志中的默认值和 true。