I'm using Ionic Framework to build an Android/iPhone cookbook app with Angular.
One of the features should be alarms/timers for each ingredient/step.
Ionic is based on a wrapper around Apache Cordova, I guess. So I've tried using a Cordova plugin, from an answer below... but it's older and it's not specifically for Ionic, and I've tried a few times but it just hasn't worked for me. I haven't found any alternatives.
doSomething() {
let successCallback = () => window.confirm('success');
let errorCallback = () => window.confirm('fail');
// set wakeup timer
(<any>window).plugins.wakeuptimer.wakeup(successCallback,
errorCallback,
// a list of alarms to set
{
alarms : [{
type : 'onetime',
time : { seconds : 5 },
extra : { message : 'json containing app-specific information to be posted when alarm triggers' },
message : 'Alarm has expired!'
}]
}
);
}
Local notifications are kind of an option, but it's just a notification. It doesn't work like a native alarm clock. (It's like getting a text, but you miss it so your burgers burn.)
Can anyone give an example of an alarm or timer in a modern Ionic app? Maybe I'm just missing something to get the plugin to work?
Or is there any kind of alternative I'm missing?
I'm getting bummed that the app is almost done but I've been stuck on this. :(
You need an alarm plugin. this one can work: https://github.com/Haggus/cordova-plugin-wakeuptimer
to set an alarm :
// set wakeup timer
window.wakeuptimer.wakeup( successCallback,
errorCallback,
// a list of alarms to set
{
alarms : [{
type : 'onetime',
time : { hour : 14, minute : 30 },
extra : { message : 'json containing app-specific information to be posted when alarm triggers' },
message : 'Alarm has expired!'
}]
}
);
The plugin you are attempting to use is almost 5 years old. Older than Ionic 2 if you using Ionic v3 and you try to install the plugin will return this erore
so the best solution for you use Local Notifications
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With