wnyc / cordova-plugin-wakeuptimer

Cordova plugin for a wakeup alarm clock
90 stars 111 forks source link

how to execute a specific function when alarm wake up ? #25

Open watio opened 7 years ago

watio commented 7 years ago

Hello, tank you for this plugin. i would like to now how to execute a specific function when alarm wakeup. exemple: i would like to execute my function test when alarm wake up but it don't work. can you help me please? this ismy code:

function alarm(date, heure, min){

    var successCallback = function(result) {
        if (result.type==='wakeup') {
            test();
            //console.log('wakeup alarm detected--' + result.extra);

        } else if(result.type==='set'){
            alert('alarm initialiser');
            //console.log('wakeup alarm set--' + result);
        }else{
            alert('unkown');

        }
    };

    var errorCallback = 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 + ')');
        }
    };

    // //type : 'onetime',

        window.wakeuptimer.wakeup(successCallback,
            errorCallback,
            {
                alarms: [{
                    type: 'onetime',
                    time: {hour: heure, minute: min},
                    extra: { message: 'test'},
                    message: 'Alarm has expired!'
                }]
            }
        );

}

function test(){ alert('it is time'); }

tank you