Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to handle background permissions properly. #2037

Open
Venkatech opened this issue May 29, 2024 · 3 comments
Open

Unable to handle background permissions properly. #2037

Venkatech opened this issue May 29, 2024 · 3 comments

Comments

@Venkatech
Copy link

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
@christocracy
Copy link
Member

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

Copy link

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

@github-actions github-actions bot added the stale label Jun 29, 2024
@Venkatech
Copy link
Author

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

@github-actions github-actions bot removed the stale label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants