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

iOS doesn't throw an Enxception when the permission on request is denied by user #979

Open
fufylev opened this issue Aug 12, 2024 · 0 comments

Comments

@fufylev
Copy link

fufylev commented Aug 12, 2024

Describe the bug
iOS doesn't throw an Enxception when the permission on request is denied by user, while Android throws an Exception.

Expected behavior
When call a method location.getLocation() I expect that library react on user's action in case when user DENIED a location permission request. The same behavoir on Android currentlt exists - only iOS ignore this action.

Tested on:

  • iOS, Version 17.6 - IPhone 11 real device
  • Flutter v.3.24.0
  • location: ^7.0.0
Future<Coordinate> getLocation() async {
  Location location = Location();

  bool isServiceEnabled = false;
  PermissionStatus permissionStatus = PermissionStatus.denied;
  LocationData? locationData;

  isServiceEnabled = await location.serviceEnabled();

  if (!isServiceEnabled) {
    isServiceEnabled = await location.requestService();
    if (!isServiceEnabled) {
      throw LocationServicesNotAvailable();
    }
  }

  if (isServiceEnabled) {
    try {
      locationData = await location.getLocation();
    } catch (_) {
      // HERE we expect an Exception if user has denied the request <====
      // However iOS never reaches this line on code
      permissionStatus = await location.hasPermission();
      if (permissionStatus != PermissionStatus.granted) {
        throw LocationPermissionDenied();
      } else {
        rethrow;
      }
    }
  }

  return Coordinate(latitude: locationData?.latitude ?? 0.0, longitude: locationData?.longitude ?? 0.0);
}
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