cordova local notification plugin

cordova plugin add org.apache.cordova.device
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git && cordova prepare

1.

需要上面的两个插件 安装插件
在deviceready 设备准备好了调用插件的方法:
notification.local.add
notification.local.cancel
notification.local.cancelAll
notification.local.isScheduled
notification.local.getScheduledIds
notification.local.isTriggered
notification.local.getDefaults
notification.local.setDefaults
notification.local.onadd
notification.local.ontrigger
notification.local.onclick
notification.local.oncancel
2.具体如下:

document.addEventListener('deviceready', function () {
    // window.plugin.notification.local is now available
        var now = new Date().getTime();
    _60_seconds_from_now = new Date(now + 60 * 1000);
    window.plugin.notification.local.add({
        id: 1,
        title: 'Reminder',
        message: 'Dont forget to buy some flowers.',
        badge: 1,
        autoCancel: true,
        date: _60_seconds_from_now
    });
       window.plugin.notification.local.onclick = function(id, state, json) {

        window.plugin.notification.local.cancelAll();

    };
}, false);

  

原文地址:https://www.cnblogs.com/xieyier/p/4090240.html