PushNotification在ng-Cordova中不起作用

时间:2016-05-19 06:46:35

标签: android angularjs cordova push-notification google-cloud-messaging

我们在控制器中使用以下代码。我们按照以下步骤操作:

1)我们在项目创建时从GCM获取发件人ID

2)将发件人ID发送到GCM服务器,如下所示

angular.module('app.controllers', [])
.controller('notificationCtrl', function($scope,$cordovaPush,$rootScope) {
var androidConfig = {
    "senderID": "293702747276",
  };
document.addEventListener("deviceready", function(){
$cordovaPush.register(androidConfig).then(function(result) {
      // Success
      alert(result);
    }, function(err) {
      // Error
    })

    $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
      alert(event);

       alert('notification' + notification);

      switch(notification.event) {


        case 'registered':
          if (notification.regid.length > 0 ) {
            alert('registration ID = ' + notification.regid);
            console.log('registration ID = ' + notification.regid);
          }
          break;

        case 'message':
          // this is the actual push notification. its format depends on the data model from the push server
          alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
          break;

        case 'error':
          alert('GCM error = ' + notification.msg);
          break;

        default:
          alert('An unknown GCM event has occurred');
          break;
      }
    });

    // WARNING: dangerous to unregister (results in loss of tokenID)
    $cordovaPush.unregister(options).then(function(result) {
      // Success!
    }, function(err) {
      // Error
    })

  }, false);
            })
`

3)现在从GCM

获取注册ID

4)然后注册ID点击本地服务器点击浏览器响应获得成功但PushNotification没有进入移动

请指导我们。告诉我,我的代码中有什么问题。我们正在开发ng-Cordova移动应用

0 个答案:

没有答案