0

我有一个现有的 Telerik AppBuilder 应用程序,该应用程序以前在对应用程序进行大修之前有工作通知。该应用程序使用 Cordova 3.7.0 并试图实现 localnotifications 插件,其源代码可以在这里找到:https ://github.com/katzer/cordova-plugin-local-notifications. 我使用 Telerik 的“已验证插件”文档中指定的说明安装了它。但是,它不再起作用。通过各种警报,警报(windows.plugins)和警报(cordova.plugins)始终未定义,警报(windows.plugins.notifications)及其所有排列也是如此。我看到对其他回复的回复说 window.plugins 总是未定义和弃用,但 window.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'
                                });

that.alert(message) 是 navigator.notificaiton.alert(message, false, "COMPANY_NAME") 的快捷功能,工作正常。

为什么

4

1 回答 1

0

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

于 2016-04-01T15:32:25.490 回答