react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Unable to handle background permissions properly.

Open Venkatech opened this issue 1 year ago • 2 comments

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

  1. I had above configuration in App.tsx
  2. 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

Venkatech avatar May 29 '24 16:05 Venkatech

See api docs event .onProviderChange to subscribe to changes in location permission.

christocracy avatar May 29 '24 16:05 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jun 29 '24 01:06 github-actions[bot]

Thanks for your reply. I was able to handle permissions using onProviderChange. Only 2 scenarios I am facing issue

  1. when user denied permission 2 times in android, the permission denied permanently and unable to show dialog using the library. Working fine in iOS
  2. 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 image

Venkatech avatar Jul 08 '24 04:07 Venkatech

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 08 '24 01:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Aug 22 '24 01:08 github-actions[bot]