无法在pubnub javascript回调中获取错误
Not able to get error in pubnub javascript callback
我正在关注这篇博客文章中的操作方法:http://www.pubnub.com/blog/sending-android-push-notifications-via-gcm-javascript-using-phonegap/
到目前为止,我已经做了以下工作:
- 在Google开发控制台中创建了一个新项目
- 开启Android版谷歌云消息
- 已获取发件人ID(项目编号)和服务器钥匙
然后将推送插件添加到现有项目中:
$ cordova plugin add https://github.com/phonegap-build/PushPlugin.git
然后将PushNotification.js从插件中复制到我的js-lib文件夹中。我正在用requirejs加载这个js文件和pubnub-cdn,这似乎很好。
我在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
Chrome 30.0(在网络视图中)
Cordova 3.6.3-0.2.13
啊,我想我知道发生了什么-您的发件人ID必须是字符串!你可能在用它作为一个数字。
顺便说一句,谢谢你试用我写的教程:-)
相关文章:
- chrome在WebSocket握手期间获取新错误
- 在引用最新的rxjs时获取rxjs错误
- Ruby on Rails屏幕抓取错误-“;您必须在浏览器中启用javascript才能使用此应用程序"
- Twitter引导程序弹出在网站上不起作用:未获取引用错误
- 正在获取语法错误:意外的标识符和未捕获的ReferenceError
- D3 Json请求获取XmlHttpRequest错误:访问控制允许原点不允许原点为null
- 使用.content().get().nodevalue;后在firebug中获取类型错误;
- 使用hasAttribute()获取类型错误:hasAttribute不是函数
- jquery日期分析器错误获取NaN错误
- 在jquery ajax POST中获取400(错误请求)错误
- 无法在 IE 10 中获取属性错误
- jQuery 在使用 ajax 时抓取错误的形式
- 获取类型错误:无法在 angularjs 控制器中调用未定义的方法 'then'
- 未定义获取 jquery 错误 $
- AngularJS在从HTTP返回的JSON中获取语法错误.JSONP.
- 在使用日历的产品页面上的 magento 中获取“类型错误:触发器元素为空”错误
- 调用函数时获取类型错误
- 无法在节点应用程序上获取/文件名错误
- JavaScript 中的 try-catch:如何获取原始错误的堆栈跟踪或行号
- 需要获取 JavaScript 错误对象