I’m working on the onboarding process for my app, which requires background geolocation. It can’t work at all without location permission, so during the onboarding I need to make sure that the permission is granted.
I have a location provider, which handles location tracking for the whole app, however backgroundGeolocation.start()
always resolves, even when location permission is not granted. At the moment, my code looks like this:
configureBackground() {
let opts = {
desiredAccuracy: 10,
stationaryRadius: 10,
distanceFilter: 10,
pauseLocationUpdates: false,
stopOnTerminate: false
}
this.backgroundGeolocation.configure(opts).subscribe(position => {
this.ref = {
lat: position.latitude,
lng: position.longitude
}
this.pos.next(this.ref)
// confirm state updated
this.backgroundGeolocation.finish();
})
}
startTracking() {
this.configureBackground();
return this.backgroundGeolocation.start();
}
I use it as follows:
locationService.startTracking()
.then(() => {
// Go to next component of onboarding page
})
.catch(err => {
// User didn't grant location, show error page
})
.catch
is never called, even if location permission is denied.
How can I start tracking and go to an error page if permission is denied?