【问题标题】:Phonegap Build Push Notification plugin issuePhonegap 构建推送通知插件问题
【发布时间】:2013-10-14 20:56:47
【问题描述】:

我有一个非常奇怪的问题已经让我发疯了一天。我有一个 Phonegap Build 3.0 应用程序,并且正在尝试集成 Push plugin。问题是,即使我遵循文档和许多许多示例,该死的东西也行不通。我无法让它触发成功或错误回调,并且 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" />

任何帮助将不胜感激。

【问题讨论】:

  • 更新:我在 Phonegap Build 的调试模式下运行它并尝试直接调用 myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"}); 并且日志显示它返回未定义,而调用 myPushNotification = window.plugins.pushNotification; 会返回应有的对象。

标签: cordova push-notification phonegap-plugins phonegap-build


【解决方案1】:

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

【讨论】:

  • 我遇到了 Dom 的确切问题,但仍然无法解决,我在我的应用程序中尝试了匿名函数和回调函数仍然没有运气,我仍然不明白如何你让它工作了吗?这是我的主题stackoverflow.com/questions/22350971/…
猜你喜欢
  • 1970-01-01
  • 2014-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多