Commit f678a201 by Jeroen Weener Committed by GitHub

Remove callback on undetermined location status (#1089)

* Removes callback on undetermined location status

* Only ignore first `kCLAuthorizationStatusNotDetermined`
parent a5c2862e
## 9.1.3
* Fixes an issue where the `Permission.location.request()`, `Permission.locationWhenInUse.request()` and `Permission.locationAlways.request()` calls returned `PermissionStatus.denied` regardless of the actual permission status.
## 9.1.2 ## 9.1.2
* Fixes an issue where the `Permission.locationAlways.request()` call hangs when the application was granted "Allow once" permissions for fetching location coordinates. * Fixes an issue where the `Permission.locationAlways.request()` call hangs when the application was granted "Allow once" permissions for fetching location coordinates.
......
...@@ -17,6 +17,7 @@ NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_ha ...@@ -17,6 +17,7 @@ NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_ha
CLLocationManager *_locationManager; CLLocationManager *_locationManager;
PermissionStatusHandler _permissionStatusHandler; PermissionStatusHandler _permissionStatusHandler;
PermissionGroup _requestedPermission; PermissionGroup _requestedPermission;
BOOL _previousStatusWasNotDetermined;
} }
- (instancetype)initWithLocationManager { - (instancetype)initWithLocationManager {
...@@ -24,6 +25,7 @@ NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_ha ...@@ -24,6 +25,7 @@ NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_ha
if (self) { if (self) {
_locationManager = [CLLocationManager new]; _locationManager = [CLLocationManager new];
_locationManager.delegate = self; _locationManager.delegate = self;
_previousStatusWasNotDetermined = NO;
} }
return self; return self;
...@@ -98,19 +100,28 @@ NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_ha ...@@ -98,19 +100,28 @@ NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_ha
// This is called when the location manager is first initialized and raises the following situations: // This is called when the location manager is first initialized and raises the following situations:
// 1. When we first request [PermissionGroupLocationWhenInUse] and then [PermissionGroupLocationAlways] // 1. When we first request [PermissionGroupLocationWhenInUse] and then [PermissionGroupLocationAlways]
// this will be called when the [CLLocationManager] is first initialized with // this will be called when the [CLLocationManager] is first initialized with
// [kCLAuthorizationStatusAuthorizedWhenInUse]. As a consequence we send back the result to early. // [kCLAuthorizationStatusAuthorizedWhenInUse]. As a consequence we send back the result too early.
// 2. When we first request [PermissionGroupLocationWhenInUse] and then [PermissionGroupLocationAlways] // 2. When we first request [PermissionGroupLocationWhenInUse] and then [PermissionGroupLocationAlways]
// and the user doesn't allow for [kCLAuthorizationStatusAuthorizedAlways] this method is not called // and the user doesn't allow for [kCLAuthorizationStatusAuthorizedAlways] this method is not called
// at all. // at all.
// 3. When the permission dialog is opened, this method is called with [kCLAuthorizationStatusNotDetermined].
// The method should not return at this point, but instead wait for the next [CLAuthorizationStatus] to
// determine what to send back. If the method is called with [kCLAuthorizationStatusNotDetermined] for a
// second time, assume that the permission was not granted. This might catch situations where the user
// dismisses the dialog without making a decision.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (_permissionStatusHandler == nil || @(_requestedPermission) == nil) { if (_permissionStatusHandler == nil || @(_requestedPermission) == nil) {
return; return;
} }
if (status == kCLAuthorizationStatusNotDetermined) { if (status == kCLAuthorizationStatusNotDetermined) {
if (_previousStatusWasNotDetermined) {
_permissionStatusHandler(PermissionStatusDenied); _permissionStatusHandler(PermissionStatusDenied);
}
_previousStatusWasNotDetermined = YES;
return; return;
} }
_previousStatusWasNotDetermined = NO;
if ((_requestedPermission == PermissionGroupLocationAlways && status == kCLAuthorizationStatusAuthorizedWhenInUse)) { if ((_requestedPermission == PermissionGroupLocationAlways && status == kCLAuthorizationStatusAuthorizedWhenInUse)) {
_permissionStatusHandler(PermissionStatusDenied); _permissionStatusHandler(PermissionStatusDenied);
......
...@@ -2,7 +2,7 @@ name: permission_handler_apple ...@@ -2,7 +2,7 @@ name: permission_handler_apple
description: Permission plugin for Flutter. This plugin provides the iOS API to request and check permissions. description: Permission plugin for Flutter. This plugin provides the iOS API to request and check permissions.
repository: https://github.com/baseflow/flutter-permission-handler repository: https://github.com/baseflow/flutter-permission-handler
issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues
version: 9.1.2 version: 9.1.3
environment: environment:
sdk: ">=2.15.0 <4.0.0" sdk: ">=2.15.0 <4.0.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment