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

getProviderState getting incorrect enabled flag for iOS #2212

Open
sainjay opened this issue Nov 22, 2024 · 2 comments
Open

getProviderState getting incorrect enabled flag for iOS #2212

sainjay opened this issue Nov 22, 2024 · 2 comments

Comments

@sainjay
Copy link

sainjay commented Nov 22, 2024

Your Environment

  • Plugin version: 4.17.4

  • Platform: iOS

  • OS version: 18.1.1

  • Device manufacturer / model: iPhone 16 Pro

  • React Native version (react-native -v):

  • expo-env-info 1.2.1 environment info:
    System:
    OS: macOS 15.1.1
    Shell: 5.9 - /bin/zsh
    Binaries:
    Node: 22.4.1 - ~/.nvm/versions/node/v22.4.1/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v22.4.1/bin/npm
    Watchman: 2024.11.11.00 - /opt/homebrew/bin/watchman
    Managers:
    CocoaPods: 1.16.2 - /opt/homebrew/bin/pod
    SDKs:
    iOS SDK:
    Platforms: DriverKit 24.1, iOS 18.1, macOS 15.1, tvOS 18.1, visionOS 2.1, watchOS 11.1
    Android SDK:
    API Levels: 28, 32, 33, 34, 35
    Build Tools: 30.0.3, 33.0.0, 33.0.1, 34.0.0, 35.0.0
    System Images: android-34 | Google APIs ARM 64 v8a
    IDEs:
    Android Studio: 2024.2 AI-242.23339.11.2421.12550806
    Xcode: 16.1/16B40 - /usr/bin/xcodebuild
    npmPackages:
    expo: ^51.0.11 => 51.0.26
    expo-router: ~3.5.23 => 3.5.23
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    react-native: 0.74.5 => 0.74.5
    react-native-web: ~0.19.6 => 0.19.12
    Expo Workflow: bare

  • Plugin config

export const defaultReadyOptions: Config = {
  // Debug
  debug: false,
  logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
  distanceFilter: 10,
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  stopOnTerminate: false,
  startOnBoot: true,
  stopOnStationary: false,
  disableAutoSyncOnCellular: false,
  useSignificantChangesOnly: false,
  // Location permission
  locationAuthorizationRequest: "Always",

  enableHeadless: false,
  backgroundPermissionRationale: {
    title: "Confirm your location permissions",
    message:
      "“Allow all the time“ enables John Hancock to collect your location only during a session. We do not collect your location data once you select “End Session“.",
    positiveAction: "Change to {backgroundPermissionOptionLabel}",
    negativeAction: "Cancel",
  },
  // Location settings permissions alert, when Location is set to `Never` manually
  locationAuthorizationAlert: {
    titleWhenNotEnabled: "Location services not enabled",
    titleWhenOff: "Location services are off",
    instructions:
      "To use CareGiver optimally, you must enable 'Always' in Location Services settings",
    cancelButton: "Cancel",
    settingsButton: "Settings",
  },
};

Expected Behavior

For Android, in const providerState = await BackgroundGeolocation.getProviderState();

enabled is false when Device location permission is off
enabled is true when Device location permission is on

expecting the same behavior in iOS

Actual Behavior

enabled is true when Device location permission is off
enabled is true when Device location permission is on

Steps to Reproduce

  1. const providerState = await BackgroundGeolocation.getProviderState();
  2. console.log("Provider State: ", providerState);
  3. On Android, getting expected result for enabled flag
  4. But on iOS, getting it as true regardless of the device location permission on or off

Context

Trying to capture the accurate permission type for both Android and iOS:

if (!providerState.enabled) {
// The user has disabled location services for the device
permissionType = LocationPermissionType.DEVICE_OFF;
} else {
switch (providerState.status) {
case 0:
// The user has not chosen whether the app can use location services
permissionType = LocationPermissionType.NOT_DETERMINED;
break;

  case 1:
    // The user cannot change this app’s status, possibly due to active restrictions such as parental controls being in place
    permissionType = LocationPermissionType.RESTRICTED;
    break;

  case 2:
    permissionType = LocationPermissionType.APP_OFF;
    // The user denied the use of location services for the app or they are disabled globally in Settings
    break;

  case 3:
    // The user authorized the app to start location services at any time
    permissionType = LocationPermissionType.ALWAYS;
    break;

  case 4:
    // Allow Once also translates into Allow while using the app
    // The user authorized the app to start location services while it is in use
    permissionType = LocationPermissionType.WHEN_IN_USE;
    break;

  default:
    permissionType = LocationPermissionType.OTHER;
}

}

Debug logs

Logs
PASTE_YOUR_LOGS_HERE
@sainjay
Copy link
Author

sainjay commented Nov 22, 2024

in iOS, with status: 2, enabled becomes false. isn't that incorrect?

Provider State:  {"accuracyAuthorization": 1, "enabled": false, "gps": true, "network": true, "status": 2}

@sainjay
Copy link
Author

sainjay commented Nov 26, 2024

@christocracy looking for advice and workarounds for this?
working as expected in Android but not in iOS

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

1 participant