I have a problem and hope some can give me some insight on what I’m doing wrong.
I start with a blank Ionic tabs app and then add the Cordova geofence plugin (https://github.com/cowbell/cordova-plugin-geofence) via cordova plugin add cordova-plugin-geofence
Inside my app.js I try to initialize it via
But this doesn’t work. In my browser console it says: “window.geofence is undefined”.
I’ve seen the ionic sample app but found it not really helpful as the app is quite complex already. I want to recreate this step by step in order to improve my skills.
I have tried the following… but still I get the error that window.geofence is undefined… I don’t think it has something to do with how the method is called. Even with the 10 seconds timeout I can catch the console output but still get the undefined error.
.run(function($ionicPlatform) {
document.addEventListener('deviceready', function () {
// window.geofence is now available
window.geofence.initialize();
}, false);
setTimeout(function() {
console.log('test1');
window.geofence.initialize();
console.log('test');
console.log(window.geofence);
}, 10000);
$ionicPlatform.ready(function() {
…
});
})
Ionic View doesn’t contain all Cordova plugins so I can imagine it doesn’t work. I think you need to do “ionic build” or “ionic run” with a real device.
I can’t get them to work them when I’m using an Ionic workflow but I can get them to work using a Cordova workflow
What I Do:
Create an Ionic app with $ionic start geotest
Install one of the plugins as described on their github repo
when I try to initialize them, I get the error described in my first post, that the object is undefined
When using a Cordova workflow (cordova create geotest and installing one the pf the plugins as described on their repo I can access the object and everything seems to work fine).
Can somebody tell me what I’m doing wrong here? I never experienced this behaviour before with other plugins.