I tried to do it based on the code of that site: link
But when I hit the "Add notification" button this error appears:
ionic.bundle.js:26771 ReferenceError: device is not defined
at Scope.$scope.add (controllers.js:83)
at fn (eval at <anonymous> (ionic.bundle.js:27615), <anonymous>:4:200)
at ionic.bundle.js:65290
at Scope.$eval (ionic.bundle.js:30372)
at Scope.$apply (ionic.bundle.js:30472)
at HTMLButtonElement.<anonymous> (ionic.bundle.js:65289)
at defaultHandlerWrapper (ionic.bundle.js:16764)
at HTMLButtonElement.eventHandler (ionic.bundle.js:16752)
at triggerMouseEvent (ionic.bundle.js:2953)
at tapClick (ionic.bundle.js:2942)
And when I press the "Is Scheduled" button this error appears:
ionic.bundle.js:26771 TypeError: Cannot read property 'plugins' of undefined
at Object.isScheduled (ng-cordova.min.js:8)
at Scope.$scope.isScheduled (controllers.js:97)
at fn (eval at <anonymous> (ionic.bundle.js:27615), <anonymous>:4:224)
at ionic.bundle.js:65290
at Scope.$eval (ionic.bundle.js:30372)
at Scope.$apply (ionic.bundle.js:30472)
at HTMLButtonElement.<anonymous> (ionic.bundle.js:65289)
at defaultHandlerWrapper (ionic.bundle.js:16764)
at HTMLButtonElement.eventHandler (ionic.bundle.js:16752)
at triggerMouseEvent (ionic.bundle.js:2953)
Searching the internet I found that Cordova from version 4.0 to use this type of feature needs the Whitelist for secure access to external domains I'm not sure of that but I still installed this plugin and added in index.html this tag:
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
and it still does not work.
The template looks like this:
<ion-content>
<button class="button" ng-click="add()">Add notification</button>
<button class="button" ng-click="isScheduled()">Is Scheduled</button>
</ion-content>
The script looks like this:
app.controller('AlarmeCtrl', function ($scope, $cordovaLocalNotification, $ionicPlatform) {
//Notificações locais do Alarme
$scope.add = function () {
var alarmTime = new Date();
alarmTime.setMinutes(alarmTime.getMinutes() + 1);
var sound = device.platform == 'Android' ? 'file:C:\Users\knot\Music\I Stand Alone (2014_12_11 04_07_36 UTC).mp3' : 'file://beep.caf';
$cordovaLocalNotification.add({
id: "1234",
date: alarmTime,
message: "This is a message",
title: "This is a title",
autoCancel: true,
sound: sound,
}).then(function () {
console.log("The notification has been set");
});
};