Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling a native alarm/timer

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. :(

like image 467
RJB Avatar asked Mar 03 '23 11:03

RJB


2 Answers

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!'
       }]
   }
);
like image 174
devseo Avatar answered Mar 13 '23 05:03

devseo


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

enter image description here

so the best solution for you use Local Notifications

Good luck.

like image 37
Younes Zaidi Avatar answered Mar 13 '23 05:03

Younes Zaidi