3
I tried to do based on the code of this site: https://devdactic.com/local-notifications-ionic/
But when I press 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 kind of resource needs Whitelist for safe access to external domains I’m not sure 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 yet it doesn’t 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>
Script looked 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");
});
};
I’m trying to use the emulator but when I type the commands in the Node terminal this appears: C: Users Knot Desktop Climate Alarm>Ionic build android Error: Unexpected token C: Users Knot Desktop Climate Alarm>Ionic emulate android Error: Unexpected token C: Users Knot Desktop Climate Alarm> And already includes the folder "Platform-tools" and "tools" in the Windows PATH. I tried to use genymotion only it’s the same and I can’t use my phone at the moment.
– knot
can execute the command "Ionic info" and add the result to your reply please?
– LF Ziron