我试图为我的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 ');
});
});
});