phonegap local notification - daily

无人久伴 提交于 2019-12-08 04:52:44

问题


In the phonegap plugin developed by https://github.com/katzer/cordova-plugin-local-notifications if I want to schedule a daily notification at 14:00, how should set for the paras? What should I put for date?

window.plugin.notification.local.add({
    id:         String,  // A unique id of the notifiction
    date:       Date,    // This expects a date object
    message:    String,  // The message that is displayed
    title:      String,  // The title of the message
    repeat:     String,  // Either 'secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'
    badge:      Number,  // Displays number badge to notification
    sound:      String,  // A sound to be played
    json:       String,  // Data to be passed through the notification
    autoCancel: Boolean, // Setting this flag and the notification is automatically canceled when the user clicks it
    ongoing:    Boolean, // Prevent clearing of notification (Android only)
}, callback, scope);

Thanks Hammer


回答1:


The following example shows how to schedule a local notification which will be triggered every day, 60 seconds from now.

  var d = new Date();
  d.setHours(14); 

window.plugin.notification.local.add({
    id:      1,
    title:   'Reminder',
    message: 'Dont forget to buy some flowers.',
    repeat:  'daily',
    date:    d
});



回答2:


You have to do like this

var d = new Date();
d.setHours(14);
d.setMinutes(0);
d.setSeconds(0);

    window.plugin.notification.local.add({
        id:         "123",  // A unique id of the notifiction
        date:       d,    // This expects a date object
        message:    "you message",  // The message that is displayed
        title:      "Your message",  // The title of the message
        repeat:    'daily', //this will repeat daily at 14:00 time
        autoCancel: true,
    }, callback, scope);


来源:https://stackoverflow.com/questions/24371391/phonegap-local-notification-daily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!