【问题标题】:Schedule a local notification every day with phonegap cordova每天使用 phonegap cordova 安排本地通知
【发布时间】:2015-04-12 11:00:43
【问题描述】:

我正在使用 cordova 开发一个应用程序,我正在使用这个插件来安排每天到 6 点的本地通知 https://github.com/katzer/cordova-plugin-local-notifications

一切正常,这是我用来设置通知的代码

/*Set 6 o'clock*/
function setTestAlarm() {
    var notify = new Date();
    notify.setHours(18,00,00,00);

  localNotification.add({
        id:      1,
        title:   'My app',
        message: 'Hi this is a notification',
        repeat:  'daily',
        date:    notify,
        autoCancel: true, 
        ongoing: true, 
    });

我在做测试,通知每天下午 6 点出现,但只连续 9 天出现,然后停止出现。我做错了什么?

谢谢

【问题讨论】:

    标签: cordova notifications phonegap-plugins localnotification


    【解决方案1】:

    虽然晚了,但请尝试以下方式:https://github.com/katzer/cordova-plugin-local-notifications/wiki/11.-Samples

    cordova.plugins.notification.local.schedule({
        id: 1,
        text: "Good morning!",
        firstAt: tomorrow_at_6_am,
        every: "day" // "minute", "hour", "week", "month", "year"
    });
    

    对于tomorrow_at_6_am,您可以尝试以下操作:

    var today = new Date();
    var tomorrow = new Date();
    tomorrow.setDate(today.getDate()+1);
    tomorrow.setHours(6);
    tomorrow.setMinutes(0);
    tomorrow.setSeconds(0);
    var tomorrow_at_6_am = new Date(tomorrow);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多