Push notification phonegap pushwoosh插件注册器设备回调函数在android上永远不会启动

Push notification phonegap pushwoosh插件注册器设备回调函数在android上永远不会启动,push-notification,phonegap-build,pushwoosh,Push Notification,Phonegap Build,Pushwoosh,我正在尝试使用Pushwoosh Push Notifications phonegap构建插件,但registerDevice回调从未在我的android设备上启动,但是initPushwoosh函数确实启动了,因为我在下面的代码中看到了调用alert(“initPushwoosh”)的警报 下面是我的config.xml <?xml version="1.0" encoding="UTF-8"?> <!-- config.xml reference: https://bu

我正在尝试使用Pushwoosh Push Notifications phonegap构建插件,但registerDevice回调从未在我的android设备上启动,但是initPushwoosh函数确实启动了,因为我在下面的代码中看到了调用alert(“initPushwoosh”)的警报

下面是我的config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->
<widget xmlns     = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "com.phonegap.hello-world"
        version   = "1.0.0">

    <name>Push notification</name>

    <description>
        Camera example app.
    </description>

    <author href="http://phonegap.com" email="support@phonegap.com">
        PhoneGap Team
    </author>

    <preference name="phonegap-version" value="3.3.0" /> 

    <gap:plugin name="org.apache.cordova.core.camera" />

     <plugin name="PushNotification"
        value="com.pushwoosh.plugin.pushnotifications.PushNotifications" onload="true"/>

     <access origin="*.pushwoosh.com" />
</widget>

任何帮助都将不胜感激。。。谢谢

您是否使用最新版本的插件?如果是,请查看最新指南:

它最近已更改,initPushwoosh函数如下所示:

function initPushwoosh()
{
    var pushNotification = window.plugins.pushNotification;

    //set push notifications handler
    document.addEventListener('push-notification', function(event) {
        var title = event.notification.title;
        var userData = event.notification.userdata;

        if(typeof(userData) != "undefined") {
            console.warn('user data: ' + JSON.stringify(userData));
        }

        navigator.notification.alert(title);
    });

    //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
    pushNotification.onDeviceReady({ projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID" });

    //register for pushes
    pushNotification.registerDevice(
        function(status) {
            var pushToken = status;
            console.warn('push token: ' + pushToken);
        },
        function(status) {
            console.warn(JSON.stringify(['failed to register ', status]));
        }
    );
}

此外,您可能还需要仔细检查AndroidManifest.xml。不幸的是,它很容易出错:((

Cordova已将window.plugins替换为函数Cordova.require())您需要查找定义插件的命名空间。对于pushwoosh,它是:“com.pushwoosh.plugins.pushwoosh.PushNotification”

因此,不是:

var PushNotification = window.plugins.PushNotification;
试试这个:

var PushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");

着色器,我正在使用phonegap构建,所以我的理解是,我所需要做的就是添加这两行(如下所示)到config.xl文件,phonegap构建将使用最新的pushwoosh插件,并为我创建AdroidManifest.xml文件…您是否为此成功使用phonegap构建?问题是windows.plugins未定义,因此显然window.plugins.PushNotification未定义,应用程序在这一行爆炸r pushNotification=window.plugins.pushNotification;我明白了,对于PGB,请使用原始代码,PGB上的插件尚未更新(与PGB团队一起使用了很长时间)。在config.xml中,您的输入是不正确的。应该是这样的:我尝试在我的config.xml中同时使用这两个选项,但我得到了相同的错误,即window.splugin未使用任何一个选项定义
var PushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");