cordovaLocalNotification:click state.go 无效

cordovaLocalNotification:click state.go does not work

我试图为我的 ionic cordova 应用程序设置本地通知,但是当我点击重定向到主页时不起作用:这是我的控制器:

app.controller('notificationCtrl', function($scope, $rootScope, $ionicPlatform, $cordovaLocalNotification, $state){
      $scope.add = function() {
        var alarmTime = new Date();
        alarmTime.setMinutes(alarmTime.getMinutes() + 1);
        $cordovaLocalNotification.add({
            id: 1,
            date: alarmTime,
            message: "Bonjour",
            title: "nouvelle commande",
            autoCancel: true,
            sound: null
        }).then(function () {
            alert("The notification has been set");
        });
    };
     $rootScope.$on('$cordovaLocalNotification:click',
    function (event, notification, state) {
      $state.go('home');
      alert('ok then ');
    });

});

根据 Docs,您必须在 $ionicPlatform.ready() 中执行此操作, 如果应用不是 运行.

,则在设备就绪后也会调用点击事件
app.controller('NotificationCtrl', function($scope, $rootScope, $ionicPlatform, $cordovaLocalNotification, $state){

 $ionicPlatform.ready(function () {

  $scope.add = function() {
    var alarmTime = new Date();
    alarmTime.setMinutes(alarmTime.getMinutes() + 1);
    $cordovaLocalNotification.add({
        id: 1,
        date: alarmTime,
        message: "Bonjour",
        title: "nouvelle commande",
        autoCancel: true,
        sound: null
    }).then(function () {
        alert("The notification has been set");
    });
  };

  $rootScope.$on('$cordovaLocalNotification:click',
   function (event, notification, state) {
    $state.go('home');
    alert('ok then ');
  });

 });
});