我如何获得本地通知插件才能在我的cordova应用程序上使用?

时间:2019-12-04 18:40:50

标签: javascript android cordova cordova-plugins phonegap-build

我正在使用cordova-plugin-local-notification,我希望该通知在setReminder()函数上触发。请我怎么做

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
    this.receivedEvent('deviceready');
    document.getElementById("setreminder").addEventListener("click", setReminder);
    cordova.plugins.notification.local.registerPermission(function (granted) {
    });
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
    StatusBar.overlaysWebView(false);
    StatusBar.backgroundColorByHexString('#4281F5');
    StatusBar.styleDefault();
    document.getElementById("setreminder").addEventListener("click", setReminder);
                   var sound = "js/when.mp3";
                   var date = new Date();
                function setReminder() {
                    cordova.plugins.notification.local.schedule({
                    id: 1,
                    title: "IKD-FAD",
                    message: "Your Bus Is Almost Here!",
                    at: date,
                    sound: sound,
                    icon: "js/citybus.png"
                });
                }
    }
};

app.initialize();

1 个答案:

答案 0 :(得分:0)

document.addEventListener("deviceready", ondeviceready, false);
        function ondeviceready() {

        }
function setReminder(btn) {
            navigator.vibrate(1000);
            cordova.plugins.notification.local.schedule({
            id: 1,
            title: btn.dataset.name,
            text: "Your Bus Will Be At The Station In " + changedTime + " Minutes",
            trigger: { in: btn.dataset.diff, unit: 'minute' },
            sound: "file://js/when.mp3",
            icon: "file://img/mmArtboard.png"
            });

这对我来说是固定的