I do not quite understand the differences between the ionic backgroundgeoloaction plugin's API stop() and finish(). As the documentary description in below: finish() is used for iOS only. Do I need to always add it into the configure() function for iOS app?
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse } from '@ionic-native/background-geolocation';
constructor(private backgroundGeolocation: BackgroundGeolocation) { }
...
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
this.backgroundGeolocation.configure(config)
.subscribe((location: BackgroundGeolocationResponse) => {
console.log(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.
this.backgroundGeolocation.finish(); // FOR IOS ONLY
});
// start recording location
this.backgroundGeolocation.start();
// If you wish to turn OFF background-tracking, call the #stop method.
this.backgroundGeolocation.stop();
stop() function
This function stops the plugin. It acts like a switch. You can use it when the user deactivate this functionality or when you don't need it anymore.
finish() function
This function indicates to the OS that the task (to obtain the current location) is finished. As the plugin is still running, it will have other tasks like this one later (until the next time it needs location, maybe a few seconds later). For each task, you have to indicate to the OS that the task is finished, when it is.
Whithout this function call, IOS will keep the connection open with the plugin. So, as indicated in the doc, for an IOS app, you must always use it, in this plugin, in the callback function.
Tell me if I am not clear enough.