Cordova/Window.plugins undefined

Cordova/Window.plugins undefined

本文关键字:undefined plugins Window Cordova      更新时间:2023-11-08

我有一个现有的Telerik AppBuilder应用程序,在对该应用程序进行重大检修之前,该应用程序以前有工作通知。该应用程序使用Cordova 3.7.0,并试图实现localnotifications插件,其源代码可在此处找到:https://github.com/katzer/cordova-plugin-local-notifications。我使用Telerik的"验证插件"文档中指定的说明安装了它。但是,它不再起作用。通过各种警报,警报(windows.plugins)和警报(cordova.plugings)总是未定义的,警报(windows.plugins.notifications)及其所有排列也是如此。我看到其他回复的回复说window.plugins总是未定义和不推荐使用的,但windows.plugins.[PLUGIN_NAME]会存在。然而,情况似乎并非如此,这反而破坏了javascript。以下是当前正在使用的代码

define(['jQuery', 'base64'], function ($, base64) {
....
var that = this;
that.alert("starting");
document.addEventListener("deviceready", function() {
that.alert(JSON.stringify(window.plugins));
}, false);
....
}

以前的功能代码是

        if (that.hasNotificationPlugin()) {
            that.clearNotifications(function() {
                console.info('Setting notifications');
                // Schedule notifications for each day from the schedule
                $.each(data.DeliveryDaysThisWeek, function (i, day) {
                    var dow = day.DayOfWeek;
                    // Schedule notifications for each store within a day
                    $.each(day.Stores, function (i, store) {
                        // Only schedule the notification if the user 
                        // hasn't disabled notifications for this store
                        if (that.get('notification' + store.StoreId) !== 'false') {
                            var cutoffDate = new Date(store.CutOffDateTime);
                            var cutoffString = $.format.date(cutoffDate, 'h:mm a');
                            // Schedule it 30 minutes before the cutoff time
                            // or using the user defined time
                            var time = parseInt(that.get('notificationTime'));
                            if (isNaN(time)) {
                                that.set('notificationTime', "30");
                                time = 30;
                            }
                            var notifDate = new Date(cutoffDate.getTime() - time * 60 * 1000);
                            // Only schedule it if it's in the future
                            if (notifDate > new Date()) {
                                window.plugin.notification.local.add({
                                    id: (dow * 100000 + store.DeliveryTimes[0].DeliveryTimeId).toString(),
                                    date: notifDate,
                                    message: "The cutoff time is almost up! Place your order by " + cutoffString,
                                    title: store.Store.Restaurant.RestaurantName.trim(),
                                    json: JSON.stringify({StoreId: store.StoreId}),
                                    icon: 'icon'
                                });

alert(message)是navigator.noticaiton.alert(message,false,"COMPANY_NAME")的快捷函数,工作正常。

为什么

这个插件使用cordova.plugins...window.plugin...,你能试试吗?请参阅负责此的代码行