大佬教程收集整理的这篇文章主要介绍了Cordova PushPlugin注册获得ERROR,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var pushNotification = window.plugins.pushNotification; pushNotification.register( successHandler,errorHandler,{ 'senderID':'projectID' } ); function successHandler(result) { alert('success: '+ result); } function errorHandler(error) { alert('Error: '+ error); }
但是这个推送通知寄存器调用errorHandler函数.它显示错误消息“Class Not Found”.
为什么我收到此错误.?
任何人请建议
新的更新
根据上面的链接,我在我的cordova项目中添加了以下代码.
function initialize() { bindEvents(); } function bindEvents() { document.addEventListener('deviceready',init,falsE); } function init() { var pushNotification = window.plugins.pushNotification; pushNotification.register(successHandler,{'senderID':'projectID','ecb':'onNotificationGCM'}); // Get your Sender ID at cloud.google.com/console } function successHandler(result) { alert('success: '+ result); } function errorHandler(error) { alert('Error: '+ error); } function onNotificationGCM(E) { switch( e.event ){ case 'registered': if ( e.regid.length > 0 ){ console.log('regid = '+e.regid); alert(e.regid); } break; case 'message': console.log(E); if (e.foreground){ alert('The room temperature is set too high') } break; case 'error': alert('Error: '+e.msg); break; default: console.log('An unkNown event was received'); break; } } initialize();
我在模拟器上运行此代码.它只是成功调用successHandler函数“OK”.它没有调用onNotificationGCM上的回调函数,我没有得到注册的ID.
我的cordova项目代码背后的实际问题是什么?
请建议我
pushNotification.register( successHandler,{ 'senderID':'your_sender_id','ecb':'onNotificationGCM' // callBACk function } );
回调函数应如下所示:
function onNotificationGCM(E) { case 'registered': if (e.regid.length > 0){ deviceRegistered(e.regid); } break; case 'message': if (e.foreground){ // When the app is running foreground. } break; case 'error': console.log('Error: ' + e.msg); break; default: console.log('An unkNown event was received'); break; }
以上是大佬教程为你收集整理的Cordova PushPlugin注册获得ERROR全部内容,希望文章能够帮你解决Cordova PushPlugin注册获得ERROR所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。