1

我正在使用teleriks驗證的LocalNotification插件將本地通知發送到運行我的應用的設備。我允許他們在通知(1-2-3或4小時)之間選擇他們喜歡的時間間隔,但是我希望這些通知在清醒時間僅觸發(所以他們不會在中間喚醒用戶?在nigth的 - 是有這樣的設置到目前爲止,該通知代碼是:將LocalNotifications設置爲僅在清醒時間觸發

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

    } 
+2

我不知道答案,但我有一個想法。您可以設置多個鬧鐘。就像4小時的間隔一樣,您可以在每天的上午10點,下午2點,下午6點,晚上10點等設置鬧鐘。這樣可以避免睡眠時間。 – AtanuCSE 2015-04-06 03:28:06

+0

當然 - 謝謝:) – Jakob 2015-04-06 08:29:27

回答

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

    } 
相關問題