如何让本地通知插件在我的科尔多瓦应用程序上工作?

Posted

技术标签:

【中文标题】如何让本地通知插件在我的科尔多瓦应用程序上工作?【英文标题】:How can i get local notifications plugin to work on my cordova app? 【发布时间】:2020-03-29 15:40:43 【问题描述】:

我正在使用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】:
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"
            );

这为我解决了问题

【讨论】:

以上是关于如何让本地通知插件在我的科尔多瓦应用程序上工作?的主要内容,如果未能解决你的问题,请参考以下文章

科尔多瓦插件本地通知和数据

科尔多瓦升级后本地通知插件损坏

在科尔多瓦本地通知中显示进度条

访问远程站点上的科尔多瓦

如何在 ionic 4 中使用电容器进行本地通知,在通知中显示图标和图像“不是科尔多瓦本地通知”

科尔多瓦推送通知插件抛出错误