简体   繁体   English

如何让本地通知插件在我的cordova 应用程序上运行?

[英]How can i get local notifications plugin to work on my cordova app?

i'm using cordova-plugin-local-notification and I want the notification to trigger on setReminder() function.我正在使用 cordova-plugin-local-notification 并且我希望通知在setReminder()函数上触发。 Please how can I do this请问我该怎么做

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();
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"
            });

This fixed it for me这为我修好了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 cordova-plugin-local-notification 中查看已安排的通知? - How can i view already scheduled notifications in cordova-plugin-local-notification? 我无法使用 cordova 计步器插件 - I can't get the cordova stepcounter plugin to work 当 Android 设备处于休眠模式时,如何让 Expo 计划(本地)通知工作? - How can I get Expo scheduled (local) notifications to work while Android device is in doze mode? katzer / cordova-plugin-local-notifications不起作用 - katzer/cordova-plugin-local-notifications not working Cordova-我怎么知道我的应用程序是使用HTML5 Geolocation API还是Cordova Geolocation插件? - Cordova - how do I know if my app is using the HTML5 Geolocation API or the cordova geolocation plugin? Cordova Firebase插件:安装新应用程序时,Apple Push通知有时不起作用 - Cordova Firebase plugin: Apple Push notifications do not work sometimes when installing a new app 我如何在我的cordova应用程序中喜欢一个Facebook页面? - How can I like a facebook page in my cordova app? 我无法使用cordova本地通知插件取消通知 - I can't cancel a notification using the cordova local notification plugin Phonegap本地通知插件不起作用 - Phonegap local notifications plugin does not work 图像未使用cordova-plugin-local-notifications附件属性显示 - Image not displaying using cordova-plugin-local-notifications attachment property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM