3

我正在通过 ionic 开发一个推送应用程序。我从离子本身遵循本教程:http ://docs.ionic.io/docs/push-from-scratch

注册用户 - 完美运行!设置推送通知不

两周前它实际上运行良好,能够做我想做的一切。我预计 ngCordova/ionic 会发生一些重大变化,但我找不到。

错误

Cannot read property 'pushNotification' of undefined

at line:         $ionicPush.register({ 

痕迹

TypeError: Cannot read property 'pushNotification' of undefined
    at Object.register (ng-cordova.js:6362)
    at init (ionic-push.js:146)
    at ionic-push.js:309
    at new Q (ionic.bundle.js:22259)
    at Q (ionic.bundle.js:22246)
    at Object.register (ionic-push.js:270)
    at Scope.$scope.pushRegister (controllers.js:60)
    at $parseFunctionCall (ionic.bundle.js:21172)
    at ionic.bundle.js:53674
    at Scope.$get.Scope.$eval (ionic.bundle.js:23228)

和代码(controllers.js)

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope, $rootScope, $ionicUser, $ionicPush) {


  // // Handles incoming device tokens
  $rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
    alert("Successfully registered token " + data.token);
    console.log('Ionic Push: Got token ', data.token, data.platform);
    $scope.token = data.token;
  });

  // // Identifies a user with the Ionic User service
  $scope.identifyUser = function() {
    console.log('Ionic User: Identifying with Ionic User service');

    var user = $ionicUser.get();
    if(!user.user_id) {
      // Set your user_id here, or generate a random one.
      user.user_id = $ionicUser.generateGUID();
    };

    // Add some metadata to your user object.
    angular.extend(user, {
      name: 'Ionitron',
      bio: 'I come from planet Ion'
    });

    // Identify your user with the Ionic User Service
    $ionicUser.identify(user).then(function(){
      $scope.identified = true;
      alert('Identified user ' + user.name + '\n ID ' + user.user_id);
    });
  };

   $scope.pushRegister = function() {
    console.log('Ionic Push: Registering user');
    alert('bla');
    // Register with the Ionic Push service.  All parameters are optional.
    $ionicPush.register({ //ERROR FIRES HERE
      canShowAlert: true, //Can pushes show an alert on your screen?
      canSetBadge: true, //Can pushes update app icon badges?
      canPlaySound: true, //Can notifications play a sound?
      canRunActionsOnWake: true, //Can run actions outside the app,
      onNotification: function(notification) {
        // Handle new push notifications here
        // console.log(notification);
        return true;
      }
    });
    alert('bla2');
  };
})

我更新了cordova,添加和删除了离子就绪监听器。我尝试在手机上运行它给出了这个错误:在此处输入图像描述

你有什么建议吗?

4

1 回答 1

4

ionic config set dev_push true在终端中尝试 。

我在这里发布了这个:https ://github.com/driftyco/ionic-push-tutorial-app/issues/7

于 2015-08-11T07:23:19.707 回答