ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.05k forks source link

window.cordova.plugins gives undefined #1152

Open shahroon opened 8 years ago

shahroon commented 8 years ago

I am having the same issue,

var wmcApp = angular.module('wmcApp', ['ionic','ionic.service.core',
'wmcControllers',
'wmcTruckMapController',
'wmcDashboardController',
'wmcFactories',
'wmcTruckMapFactory',
'wmcProductionDataFactory',
'wmcDirectives',
'ionic-timepicker',
'ui.date','ngTouch','pusher-angular','ngCordova']);

wmcApp.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
    console.log("window::::"+window); // Gives object
    console.log("window.cordova::::" + window.cordova); // Gives object
    console.log("window.cordova plugins::::" + window.cordova.plugins); // Gives Undefined
    console.log("window.StatusBar"+ window.StatusBar); //Gives Undefined
    if(window.cordova && window.cordova.plugins.Keyboard) { // App breaks here
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
    }
    var push = new Ionic.Push({
        "debug": true
    });
    push.register(function(token) {
        alert(token.token);
        console.log("Device token:",token.token);
    });
});
});

Recently started working on Push Notifications.

fretman92 commented 8 years ago

It may be because $cordovaPush uses https://github.com/phonegap-build/PushPlugin that sets window.plugins variable, but this plugin is DEPRECATED. You probably installed the newer plugin https://github.com/phonegap/phonegap-plugin-push, which useswindow.PushNotification apparently instead, so window.plugins is undefined. You should use the $cordovaPushV5 factory which implements the newer plugin instead of $cordovaPush