Lyokone/flutterlocation

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

Opened this issue · 0 comments

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);
}