Hey everybody!
I’m trying to write a Alarm app using Ionic but it is not working and I don’t have any idea why. Did somebody here already used cordova-plugin-wakeuptimer? This looked like the best option to help with my alarm but I’m testing on my iPhone and it never fired a alarm.
My code is quite simple:
.factory('Alarm', function($q) {
return {
set: function() {
var d = new Date();
console.log(d);
// set wakeup timer
window.wakeuptimer.wakeup(
successCallback,
errorCallback,
// a list of alarms to set
{
alarms: [{
type: 'onetime',
time: {
hour: d.getHours(),
// adding a alarm for the next minute
minute: d.getMinutes() + 1
},
extra: {
message: 'json containing app-specific information to be posted when alarm triggers'
},
message: 'Alarm has expired!'
}]
}
);
// example of a callback method
var successCallback = function(result) {
if (result.type === 'wakeup') {
console.log('wakeup alarm detected--' + result.extra);
} else if (result.type === 'set') {
console.log('wakeup alarm set--' + result);
} else {
console.log('wakeup unhandled type (' + result.type + ')');
}
};
var errorCallback = function(err) {
console.log('Error ', err);
};
}
}
})
.controller('DemoCtrl', function($scope, Alarm) {
$scope.setAlarm = function() {
Alarm.set();
}
})
First I thought it was a foreground/background issue but I tried both and nothing worked. Than I looked the logs on xCode and it was printing:
2016-04-05 21:53:40.071 HelloCordova[1406:831180] "2016-04-06T00:53:40.055Z"
2016-04-05 21:53:40.071 HelloCordova[1406:831180] scheduling wakeups...
2016-04-05 21:53:40.089 HelloCordova[1406:831180] cancelling existing alarm notification
2016-04-05 21:53:40.090 HelloCordova[1406:831180] scheduling a new alarm local notification for 2016-04-06 00:54:00 +0000
2016-04-05 21:53:40.090 HelloCordova[1406:831180] setting alarm...
2016-04-05 21:53:40.090 HelloCordova[1406:831180] THREAD WARNING: ['WakeupPlugin'] took '18.985840' ms. Plugin should use a background thread.
So… It is logging the date correctly, creating the alarm but nothing happened after the time is up. Any ideas?