0

所以我使用這個插件:http://ngcordova.com/docs/plugins/pushNotificationsV5/這是cordovaPushV5,我試圖讓我的設備令牌發送到我的nodejs服務器。這裏是我的代碼:ngCordova錯誤保持發生

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

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

 
    var options = { 
 
    \t android: { 
 
    \t senderID: "12345679" 
 
    \t }, 
 
    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>

當我運行它離子服務(瀏覽器)我得到這個控制檯錯誤:的ReferenceError:找不到變量:PushNotification

有誰知道這是什麼意思?

+0

您無法在瀏覽器中運行該模塊。它必須在設備上運行。 –

回答

0

以上評論是100%正確的。該錯誤僅在瀏覽器中顯示,因爲此插件僅適用於設備