react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Unable to handle background permissions properly.
Your Environment
- Plugin version:
- Platform: iOS and Android
- OS version: 14
- Device manufacturer / model: Redmi
- React Native version (
react-native -v): 0.73.6 - Plugin config
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
heartbeatInterval: 60,
locationAuthorizationRequest: 'Always',
locationAuthorizationAlert: {
titleWhenNotEnabled: "Allow access to this device's location in the background",
titleWhenOff: "Allow access to this device's location in the background",
instructions:
"In order to allow location tracking, please enable 'Allow all the time permission",
cancelButton: 'Cancel',
settingsButton: 'Settings',
},
backgroundPermissionRationale: {
title: "Allow access to this device's location in the background?",
message: "In order to allow location tracking, please enable 'Allow all the time permission",
positiveAction: 'Settings',
},
foregroundService: true,
}).then(state => {
if (!state.enabled) {
if (isUserLocationTrackerEnabled) {
BackgroundGeolocation.start();
console.log('Continue tracking', state);
}
} else {
console.log('Already Enabled', state.enabled, state);
}
});
Expected Behavior
Should pop when we click some button and called .start() method and if user select allow once/while in use library should show an alert to navigate to settings to turn on allow all the time. If user selected again any other permission app should ask permissions again
Actual Behavior
but in ios not showing immediately background permission dialog. it's showing after heart beat every time.
Steps to Reproduce
- I had above configuration in App.tsx
- Calling BackgroundGeolocation.start(() => { console.log('Tracking started'); }); on a button click
3. In heart beat getting current location
useEffect(() => {
const subscription = BackgroundGeolocation.onHeartbeat(event => {
BackgroundGeolocation.getCurrentPosition({
persist: false,
maximumAge: 5000,
desiredAccuracy: 10,
}).then(location => {
console.log('[getCurrentPosition] ', location);
const locationRow = {
latitude: location.coords.latitude.toString(),
longitude: location.coords.longitude.toString(),
timestamp: location.timestamp.toString(),
};
Database.updateORInsert(Location.schema.name, [locationRow]);
});
});
}, []);
Context
We wish to buy this library but simple code failing for permissions part. even tried disabling location authorization alert but even for manual handling not able to trigger background permission dialog. Please suggest a way to handle always allow permissions for location tracking even in background
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
See api docs event .onProviderChange to subscribe to changes in location permission.
This issue is stale because it has been open for 30 days with no activity.
Thanks for your reply. I was able to handle permissions using onProviderChange. Only 2 scenarios I am facing issue
- when user denied permission 2 times in android, the permission denied permanently and unable to show dialog using the library. Working fine in iOS
- When we show Background location permission dialog when user clicked cancel there is no way we can handle that scenario in both android and ios
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.