The project is a TypeScript project.
I installed cordova-background-geolocation-lt
with
ionic plugin add cordova-background-geolocation-lt
and tried to implement it as a replacement for the older cordova-plugin-mauron85-background-geolocation
plugin, but I kept getting variations of the following error.
10 275176 group EXCEPTION: Error: Uncaught (in promise): TypeError: window.BackgroundGeolocation is undefined
I get the error even if I access it in the constructor of app.ts
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
window.BackgroundGeolocation.onMotionchange(
(isMoving) => {
console.log('[js] BackgroundGeoLocation::onMotionChange: ', isMoving);
},
(error) => {
console.log('[js] BackgroundGeoLocation::onMotionChange error: ' + JSON.stringify(error));
}
);
});
ionic info:
Cordova CLI: 6.1.1
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.6
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
OS:
Node Version: v4.4.3
ionic plugin list:
com.transistorsoft.cordova.background-geolocation 1.5.1 "BackgroundGeolocation"
cordova-plugin-console 1.0.3 "Console"
cordova-plugin-dantelo-phonestate 0.0.1 "PhoneState"
cordova-plugin-device 1.1.2 "Device"
cordova-plugin-splashscreen 3.2.2 "Splashscreen"
cordova-plugin-statusbar 2.1.3 "StatusBar"
cordova-plugin-whitelist 1.2.2 "Whitelist"
ionic-plugin-keyboard 2.0.1 "Keyboard"
Update: To reproduce the error in a few steps.
I created a new project with
ionic start Test blank --v2 --ts
cd Test
ionic plugin add https://github.com/transistorsoft/cordova-background-geolocation-lt.git
ionic platform add android
The last line adds any dependencies cordova-background-geolocation-lt
has.
I then modified app.ts by adding
declare var window:any;
after the imports, and
window.BackgroundGeolocation.onMotionchange(
(isMoving) => {
console.log('[js] BackgroundGeoLocation::onMotionChange: ', isMoving);
},
(error) => {
console.log('[js] BackgroundGeoLocation::onMotionChange error: ' + JSON.stringify(error));
}
);
to the constructor, as see above.
Running ionic serve -l -c -s
will then fail with the undefined
error mentioned above.