gpt4 book ai didi

javascript - 将 LocalNotifications 设置为仅在醒着的时候触发

转载 作者:行者123 更新时间:2023-11-28 07:27:38 26 4
gpt4 key购买 nike

我正在使用经 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;
}

}

最佳答案

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;
}

}

关于javascript - 将 LocalNotifications 设置为仅在醒着的时候触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29462873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com