Commit d1b162e2 by Lukas Kurz Committed by GitHub

Add Persistent flag for permanentlyDenied LocationAlways permission (#822)

* add persistent flag for already denied

* add missing const key

* bump permission_handler_apple to 9.0.4
parent ac5d0c48
## 9.0.4
* Add flag inside `UserDefaults` to save whether locationAlways has already been requested and prevent further requests, which would be left unanswered by the system.
## 9.0.3 ## 9.0.3
* Ensures a request for `locationAlways` permission returns a result unblocking the permission request and preventing the `ERROR_ALREADY_REQUESTING_PERMISSIONS` error for subsequent permission request. * Ensures a request for `locationAlways` permission returns a result unblocking the permission request and preventing the `ERROR_ALREADY_REQUESTING_PERMISSIONS` error for subsequent permission request.
## 9.0.2 ## 9.0.2
* Moves Apple implementation into its own package. * Moves Apple implementation into its own package.
\ No newline at end of file
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#if PERMISSION_LOCATION #if PERMISSION_LOCATION
NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_handler_apple.permission_requested";
@interface LocationPermissionStrategy () @interface LocationPermissionStrategy ()
- (void) receiveActivityNotification:(NSNotification *)notification; - (void) receiveActivityNotification:(NSNotification *)notification;
@end @end
...@@ -38,8 +40,12 @@ ...@@ -38,8 +40,12 @@
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler { - (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
PermissionStatus status = [self checkPermissionStatus:permission]; PermissionStatus status = [self checkPermissionStatus:permission];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse && permission == PermissionGroupLocationAlways) { if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse && permission == PermissionGroupLocationAlways) {
// don't do anything and continue requesting permissions BOOL alreadyRequested = [[NSUserDefaults standardUserDefaults] boolForKey:UserDefaultPermissionRequestedKey]; // check if already requested the permantent permission
} else if (status != PermissionStatusDenied) { if(alreadyRequested) {
completionHandler(status);
return;
}
} else if (status != PermissionStatusDenied) { // handles undetermined always permission and denied whenInUse permission
completionHandler(status); completionHandler(status);
return; return;
} }
...@@ -59,6 +65,7 @@ ...@@ -59,6 +65,7 @@
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil) { if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveActivityNotification:) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveActivityNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
[_locationManager requestAlwaysAuthorization]; [_locationManager requestAlwaysAuthorization];
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:UserDefaultPermissionRequestedKey];
} else { } else {
[[NSException exceptionWithName:NSInternalInconsistencyException reason:@"To use location in iOS8 you need to define NSLocationAlwaysUsageDescription in the app bundle's Info.plist file" userInfo:nil] raise]; [[NSException exceptionWithName:NSInternalInconsistencyException reason:@"To use location in iOS8 you need to define NSLocationAlwaysUsageDescription in the app bundle's Info.plist file" userInfo:nil] raise];
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# #
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'permission_handler_apple' s.name = 'permission_handler_apple'
s.version = '9.0.2' s.version = '9.0.4'
s.summary = 'Permission plugin for Flutter.' s.summary = 'Permission plugin for Flutter.'
s.description = <<-DESC s.description = <<-DESC
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
......
name: permission_handler_apple 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.
version: 9.0.3 version: 9.0.4
homepage: https://github.com/baseflow/flutter-permission-handler homepage: https://github.com/baseflow/flutter-permission-handler
environment: environment:
......
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