This is a migrated thread and some comments may be shown as answers.

Window/Cordova.plugins undefined

2 Answers 335 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carter
Top achievements
Rank 1
Carter asked on 31 Mar 2016, 08:36 PM

 I have an existing Telerik AppBuilder application that previously had working notifications before a major overhaul was done on the app. The app uses Cordova 3.7.0 and is attempting to implement the localnotifications plugin, whose source code can be found here : https://github.com/katzer/cordova-plugin-local-notifications . I installed it using the instructions specified in Telerik's "Verified Plugins" Documentation. However, it no longer functions. Through various alerts, alert(windows.plugins) and alert(cordova.plugins) is always undefined, as is alert(windows.plugins.notifications) and all permutations thereof. I saw responses to other replies saying that window.plugins would always be undefined and deprecated, but window.plugins.[PLUGIN_NAME] would exist. However, this does not seem to be the case. Below is the code current being used 

 

define(['jQuery', 'base64'], function ($, base64) {

....

var that = this;
that.alert("starting");
document.addEventListener("deviceready", function() {
that.alert(JSON.stringify(window.plugins));
}, false);

....

}

The previously functioning code was  

            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) is a shortcut function for navigator.notificaiton.alert(message, false, "COMPANY_NAME") and works fine. 

 

Why 

2 Answers, 1 is accepted

Sort by
0
Carter
Top achievements
Rank 1
answered on 31 Mar 2016, 08:55 PM

Clarification:

Cordova or window.plugins.notification breaks the code, and does not stringify to undefined.

0
Martin
Telerik team
answered on 05 Apr 2016, 02:37 PM
Hi Carter,

The latest release of the plugin (after 0.8.2) introduces a few breaking changes in the API and also requires Cordova 4.0.

As you have mentioned that you are using 3.7, could you please check which version of the plugin you are using?

If the plugin version is after 0.8.2, please upgrade your Cordova version to 4.0.


Let me know if this has worked.

Regards,
Martin
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
Apache Cordova
Asked by
Carter
Top achievements
Rank 1
Answers by
Carter
Top achievements
Rank 1
Martin
Telerik team
Share this question
or