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

标签 javascript cordova notifications localnotification telerik-appbuilder

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

相关文章:

javascript - Knockoutjs - 单击按钮时打开选择下拉菜单

javascript - thymeleaf 如何将 id 从下拉列表传递到另一个 html

android - 在 PhoneGap Build 中禁用 Android 菜单按钮

android - android中的状态栏通知

javascript - 关于 JavaScript 中的箭头函数

javascript - 是否可以获取匿名 JavaScript 函数的名称?

javascript - navigator.geolocation.getCurrentPosition 已停止工作

ios - Cordova弃用警告能否使Apple拒绝我们的应用程序?

UITableView 编辑/完成事件

android - 无法从服务中滑动删除通知