3

我有一个非常奇怪的问题让我发疯了一天。我有一个 Phonegap Build 3.0 应用程序并正在尝试集成Push 插件。问题是,即使我遵循文档和许多许多示例,该死的东西也行不通。我无法让它触发成功或错误回调,并且 try/catch 报告没有问题。

头:

<head>
    <script src="assets/js/myScripts.js"></script>
    <script src="phonegap.js"></script>
    <script type="text/javascript" src="PushNotification.js"></script>
</head>

myScripts.js

var myPushNotification;
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(){
    myPushNotification = window.plugins.pushNotification;
    try{
        myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"});
    }
    catch(e){
        alert(e.message);//******this is never fired******
    }
}

function gcmRegistrationSuccessHandler(result){
    alert("successfully registered);//******this is never fired******
}

function gcmRegistrationErrorHandler(error){
    alert("error registering");//******this is never fired******
}

config.xml 包含:

<access origin="*"/>

<gap:platform name="android" />
<gap:platform name="ios" />

<gap:plugin name="com.phonegap.plugins.pushplugin" />

任何帮助将不胜感激。

4

1 回答 1

1

问题解决了。事实证明,myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"});从未调用过“gcmRegistrationSuccessHandler”回调。仅调用“onNotificationGCM”,您必须基于此采取所有操作。当然希望记录在案......

于 2013-10-16T10:52:40.530 回答