【问题标题】:Send notification on specific time on every day in ionic v1在 ionic v1 中的每一天的特定时间发送通知
【发布时间】:2017-09-15 11:24:20
【问题描述】:

我想在 ionic v1 中每天晚上 8 点发送通知。我已经引用了以下代码,但它给出了异常。此处应使用哪种日期时间格式。我从来没有在任何地方找到完整的代码。请帮帮我。

https://github.com/katzer/cordova-plugin-local-notifications/wiki/11.-Samples

 document.addEventListener('deviceready', function () {
// Schedule notification for tomorrow to remember about the meeting
cordova.plugins.notification.local.schedule({
    id: 10,
    title: "Meeting in 15 minutes!",
    text: "Jour fixe Produktionsbesprechung",
    at: monday_9_am,
    data: { meetingId:"#123FG8" }
});

// Join BBM Meeting when user has clicked on the notification 
cordova.plugins.notification.local.on("click", function (notification) {
    if (notification.id == 10) {
        joinMeeting(notification.data.meetingId);
    }
});

// Notification has reached its trigger time (Tomorrow at 8:45 AM)
cordova.plugins.notification.local.on("trigger", function (notification) {
    if (notification.id != 10)
        return;

    // After 10 minutes update notification's title 
    setTimeout(function () {
        cordova.plugins.notification.local.update({
            id: 10,
            title: "Meeting in 5 minutes!"
        });
    }, 600000);
});
 }, false);

/**********Exception***************/
ionic.bundle.js:26794 ReferenceError: monday_9_am is not defined
at Channel.<anonymous> (controllers.js:4672)
at Channel.subscribe (cordova.js:775)
at document.addEventListener (cordova.js:133)
at HTMLDocument.document.addEventListener (cordova.js:1703)
at controllers.js:4636
at Scope.$emit (ionic.bundle.js:30645)
at Object.emit (ionic.bundle.js:58086)
at transitionComplete (ionic.bundle.js:58032)
at HTMLElement.completeOnTransitionEnd (ionic.bundle.js:58012)
at defaultHandlerWrapper (ionic.bundle.js:16787)

【问题讨论】:

    标签: cordova ionic-framework android-notifications localnotification


    【解决方案1】:

    来自here

    cordova.plugins.notification.local.schedule({
        id: 1,
        title: "Message Title",
        message: "Message Text",
        firstAt: date, // firstAt and at properties must be an IETF-compliant RFC 2822 timestamp
        every: "week", // this also could be minutes i.e. 25 (int)
        sound: "file://sounds/reminder.mp3",
        icon: "http://icons.com/?cal_id=1",
        data: { meetingId:"123#fg8" }
    });
    

    具体来说:

    // firstAt and at properties must be an IETF-compliant RFC 2822 timestamp
    

    我相信你可以创建一个 JS Date 对象,然后运行.toUTCString() 来创建一个兼容的时间戳。

    【讨论】:

      猜你喜欢
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 2019-01-01
      • 1970-01-01
      • 2022-06-11
      • 2023-01-24
      • 1970-01-01
      相关资源
      最近更新 更多