【问题标题】:ngCordova Error Keeps OccurringngCordova 错误不断发生
【发布时间】:2016-08-16 18:57:10
【问题描述】:

所以我正在使用这个插件:http://ngcordova.com/docs/plugins/pushNotificationsV5/ 这是cordovaPushV5,我正在尝试让我的设备令牌发送到我的 nodejs 服务器。这是我的代码:

angular.module('starter', ['ionic', 'ngCordova'])

.run(function($http, $cordovaPushV5) {

  var options = {
  	android: {
  	  senderID: "12345679"
  	},
    ios: {
      alert: "true",
      badge: "true",
      sound: "true"
    },
    windows: {}
  };
  
  // initialize
  $cordovaPushV5.initialize(options).then(function() {
    // start listening for new notifications
    $cordovaPushV5.onNotification();
    // start listening for errors
    $cordovaPushV5.onError();
    
    // register to get registrationId
    $cordovaPushV5.register().then(function(data) {
      // `data.registrationId` save it somewhere;
    })
  });
  
  // triggered every time notification received
  $rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){
    // data.message,
    // data.title,
    // data.count,
    // data.sound,
    // data.image,
    // data.additionalData
  });

  // triggered every time error occurs
  $rootScope.$on('$cordovaPushV5:errorOcurred', function(event, e){
    // e.message
  });

});
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <ion-content>
      </ion-content>
    </ion-pane>
  </body>
</html>

当我在 ionic serve(浏览器)中运行它时,我得到这个控制台错误:ReferenceError: Can't find variable: PushNotification

有人知道这是什么意思吗?

【问题讨论】:

  • 您无法在浏览器中运行该模块。它必须在设备上运行。

标签: angularjs ionic-framework error-handling push-notification ngcordova


【解决方案1】:

以上评论 100% 正确。该错误仅显示在浏览器中,因为此插件仅适用于设备

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2013-07-12
    • 2017-05-23
    • 1970-01-01
    • 2019-11-30
    • 2022-08-17
    • 2019-05-16
    相关资源
    最近更新 更多