Hi,
I am using the backgroundgeolocation on a ts page but the succes callback is only fired once. Can somebody tell me what the reason is for this problem?
ionic native: 3.3.7
ionic info output:
Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS
Node Version: v5.6.0
this.platform.ready().then(() => {
BackgroundGeolocation.deleteAllLocations();
BackgroundGeolocation.configure(config)
.then((location) => {
// Fired only once
this.addNewLocation(location);
// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
// BackgroundGeolocation.finish(); // FOR IOS ONLY
})
.catch((error) => {
console.log('BackgroundGeolocation error');
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
BackgroundGeolocation.start().then(log => {
console.log(log);
});
});
Might be because they return promises, they should return Observables instead.
Thanks for your reply! That was the same thing I thought :) , When do you think this problem is solved?
Changing this to be a sync since it's a non-standard behavior
@pascalrijk can you try the code in master now? Just pushed a fix that changes the semantics to be this:
BackgroundGeolocation.configure((pos) => {
}, (err) => {
}, { // options ))
Also updated the config to match the most recent version of the plugin
@mlynch: It works, thank you!
Steps to update from master:
cd node_modules/ionic-nativenpm installnpm run buildBackgroundGeolocation.configure((location) => {
console.log('Geolocation: ' + location.latitude + ',' + location.longitude + ', ' + location.speed);
BackgroundGeolocation.finish();
}, (error) => {
console.log('BackgroundGeolocation error', error);
}, config);
7 . ionic serve and run
An easier way to install from master:
npm install git+https://github.com/driftyco/ionic-native.git
Most helpful comment
Thanks for your reply! That was the same thing I thought :) , When do you think this problem is solved?