将LocalNotifications设置为仅在清醒时启动
setting LocalNotifications to only fire in waking hours
我正在使用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;
}
}
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- Meteor上的启动页面
- 如何防止网页加载后自动启动功能
- 如何从JavaScriptInterface启动Navigation Drawer
- window.on.scroll事件未启动
- 单击按钮后启动javascript提示
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- spine.js在启动时填充模型实例
- 如何在所有ng点击事件AngularJS上启动一个方法
- jQuery悬停在没有鼠标悬停的情况下启动
- SignalR客户端启动连接时如何设置用户
- Meteor:在启动时将html注入客户端文件
- Angular UI启动日期选择器问题
- 如何用低音量自动启动Youtube视频(iframe)
- jQuery mouseup在拖离链接后未启动
- 在同一选项卡中启动下载,而无需在Javascript中打开新选项卡或窗口
- 为什么我的控制器没有启动函数.js脚本
- 将LocalNotifications设置为仅在清醒时启动