没能获得错误pubnub JavaScript回调

问题描述:

我在这篇博客的HOWTO如下:http://www.pubnub.com/blog/sending-android-push-notifications-via-gcm-javascript-using-phonegap/没能获得错误pubnub JavaScript回调

截至直到现在我也做了以下内容:

  • 创建一个新的项目,谷歌开发控制台
  • 竟然在谷歌云端通讯Android的
  • 得到了发件人ID(项目编号)和服务器 关键

然后加推插件到现有项目:

$ cordova plugin add https://github.com/phonegap-build/PushPlugin.git 

从插件到我的js的lib文件夹然后复制PushNotification.js。 我加载这个js文件和pubnub cdn与requirejs,这似乎工作正常。

我在howto中创建了一个包含2.2中脚本的模块。

define(['env-config','datastore/localstore','jquery','push','pubnub'],function (EnvConfig,Store) { 

    var pushNotification = window.plugins.pushNotification; 

    function register() { 
    pushNotification.register( 
     successHandler, 
     errorHandler, 
     { 'senderID':EnvConfig.push.senderid, 'ecb':'onNotificationGCM'} 
    ); 
    } 

    function successHandler(result) { 
    console.log('Success: '+ result); 
    } 

    function errorHandler(error) { 
    //** The following line throws: 
    //** java.lang.Long cannot be cast to java.lang.String 
    console.log('Error:' + error); 
    } 

    function onNotificationGCM(e) { 
    switch(e.event){ 
     case 'registered': 
     console.log("Device registered with id "+e.regid); 
     Store.set("pushid"+e.regid); 
     /*if (e.regid.length > 0) { 
      deviceRegistered(e.regid); 
     } */ 
     break; 
     case 'message': 
     if (e.foreground){ 
      //What needs to be done when app is in the foreground 
      //while receiving a notification 
      console.log('A notification has been received'); 
     } 
     break; 
     case 'error': 
     console.log('Error: ' + e.msg); 
     break; 
     default: console.log('An unknown event was received'); 
     break; 
    } 
    } 

    var module = { 
    init: function() { 
     register(); 
    } 
    }; 

    return module; 
}); 

当设备准备就绪时,我调用这个模块的init函数。

目前register()失败并执行errorHandler回调。但console.log失败:java.lang.Long不能转换为java.lang.String。所以我不知道下一步该怎么做...

任何指针非常感谢。

三星Galaxy S5
的是Android 4.4.2
铬30.0(在网页视图)
科尔多瓦3.6.3-0.2.13

嗯,我想我知道这是怎么回事导通 你的发件人ID必须在字符串!您可能将其用作数字。

BTW,感谢您试用本教程我写的:-)

+0

非常感谢......现在的工作:-) ......顺便说一下,我也有回调附加onNotificationGCM window对象如此问题所述:https://github.com/phonegap-build/PushPlugin/issues/313 – Jette 2015-02-09 08:37:12