离子本地通知不会触发

时间:2016-03-15 14:04:02

标签: notifications ionic-framework local

我在我的离子应用程序中添加了本地通知,因为我引用了此博客https://devdactic.com/local-notifications-ionic/,但我无法在我的手机中看到任何通知,在我的控制台中我找到了日志。

错误:

   TypeError: Cannot read property 'plugins' of undefined
        at Object.schedule (ng-cordova.min.js:8)
        at Scope.$scope.add (controllers.js:2789)
        at $parseFunctionCall (ionic.bundle.js:21172)
        at ionic.bundle.js:53674
        at Scope.$eval (ionic.bundle.js:23228)
        at Scope.$apply (ionic.bundle.js:23327)
        at HTMLButtonElement.<anonymous> (ionic.bundle.js:53673)
        at HTMLButtonElement.eventHandler (ionic.bundle.js:11841)
        at triggerMouseEvent (ionic.bundle.js:2865)
        at tapClick (ionic.bundle.js:2854)(anonymous function)
        @  ionic.bundle.js:20434(anonymous function)
        @  ionic.bundle.js:17384Scope.$apply
        @ ionic.bundle.js:23329(anonymous function)
        @ ionic.bundle.js:53673eventHandler  
        @ ionic.bundle.js:11841triggerMouseEvent
        @ ionic.bundle.js:2865tapClick
        @ ionic.bundle.js:2854tapMouseUp 
        @ ionic.bundle.js:2927

CONTROLLER

 .controller('LocalNotificationCtrl',function($scope,$cordovaLocalNotification){
       console.log('Notification entering'); 

  $scope.add = function() {
    var alarmTime = new Date();
    alarmTime.setMinutes(alarmTime.getMinutes() + 1);
    $cordovaLocalNotification.schedule({
        id: "1234",
        date: alarmTime,
        message: "This is a message",
        title: "This is a title",
        autoCancel: true,
        sound: null
    }).then(function () {
        console.log("The notification has been set");
    });
};

$scope.isScheduled = function() {
    $cordovaLocalNotification.isScheduled("1234").then(function(isScheduled) {
        alert("Notification 1234 Scheduled: " + isScheduled);
    });
}


})

查看

  <ion-content ng-controller="LocalNotificationCtrl">

        <button class="button" ng-click="add()">Add notification</button>
        <button class="button" ng-click="isScheduled()">Is Scheduled</button>
  </ion-content>

App.js

 angular.module('Mobile_App', ['ionic','ngCordova','Mobile_App.controllers','Mobile_App.services'])

.run(function($cordovaToast,$ionicHistory,$ionicPlatform, $rootScope)     {
    $ionicPlatform.ready(function() {

    if(window.cordova && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
        StatusBar.styleDefault();
    }
});

试过但无法解决,请提前帮助我。

0 个答案:

没有答案
相关问题