.controller('PushNotificationsCtrl',function ($scope,$cordovaPush) {var androIDConfig = {"senderID":"372433177444","ecb":"onNotification"};$cordovaPush.register(androIDConfig).then(function(result) { // Success! $scope.pushSuccess = result},function(err) { $scope.pushSuccess = err;});
我设法从GCM成功获得RegID.但是,我如何从androIDConfig管理onNotification?
解决方法 我找到了解决方案.而不是这样做:
var androIDConfig = {"senderID":"372433177444","ecb":"onNotification"};
我喜欢这个:
var androIDConfig = {"senderID":"372433177444","ecb":"window.onNotification"};
然后
window.onNotification = function(e) { switch( e.event ) { case 'registered': if ( e.regID.length > 0 ) { console.log("Your regID is : " + e.regID); } break; case 'message': // this is the actual push notification. its format depends on the data model from the push server console.log('message = '+e.message); angular.element(document.querySelector('#yata')).HTML(e.message); break; case 'error': console.log('GCM error = '+e.msg); break; default: console.log('An unkNown GCM event has occurred'); break; }};
现在按预期工作了:)
总结以上是内存溢出为你收集整理的ionic-framework – 如何在ngCordova push插件中处理onNotification事件全部内容,希望文章能够帮你解决ionic-framework – 如何在ngCordova push插件中处理onNotification事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)