アプリを実行しているデバイスにローカル通知を送信するために、teleriks で検証された LocalNotification プラグインを使用しています。通知の間に好みの間隔 (1-2-3 または 4 時間) を選択できるようにしますが、これらの通知が起きている時間にのみ発生するようにしたいと思います (途中でユーザーを起こさないようにします)。これに対する設定はありますか? これまでのところ、通知コードは次のとおりです。
app.notify({
id : 4,
title : 'Remember',
message : '.. until you cancel all notifications',
repeat : 60*this.get('notification_interval'),
autoCancel : true,
date : new Date(new Date().getTime() + 60*60*1000*this.get('notification_interval'))
},function(){alert('you will recieve a message every '+this.get('notification_interval')+'. hour');});
編集
AtanuCSE による優れたコメントに基づいて、コードを編集したので、次のようになりました。
app.setupnotificationinterval(interval)
{
//set hour to 10 for starting hour
var hour = 10;
//set a notificationDate time.
var notificationDate = new Date().getTime();
//manipulate the dateobject to fit, 10:00:00
notificationDate.setMinutes(0);notificationDate.setSeconds(0);
//loop as long as the notification hour interval doesnt exceed 12 hours (from 10-22).
while(hour < 22)
{
notificationDate.setHours(hour);
this.notify({
id : hour,
title : 'Husk at registrere energi',
message : 'Det er tid til at du skal registrere din energi',
repeat : 'daily',
autoCancel : true,
date : notificationDate
},function(){alert('alarm sat til kl. ' + notificationDate.getHour());});
hour = hour + interval;
}
}