Skip to content

Commit

Permalink
Add Persistent flag for permanentlyDenied LocationAlways permission (#…
Browse files Browse the repository at this point in the history
…822)

* add persistent flag for already denied

* add missing const key

* bump permission_handler_apple to 9.0.4
  • Loading branch information
lukaskurz committed Mar 31, 2022
1 parent ac5d0c4 commit d1b162e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion permission_handler_apple/CHANGELOG.md
@@ -1,7 +1,11 @@
## 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

* 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

* Moves Apple implementation into its own package.
* Moves Apple implementation into its own package.
Expand Up @@ -7,6 +7,8 @@

#if PERMISSION_LOCATION

NSString *const UserDefaultPermissionRequestedKey = @"org.baseflow.permission_handler_apple.permission_requested";

@interface LocationPermissionStrategy ()
- (void) receiveActivityNotification:(NSNotification *)notification;
@end
Expand Down Expand Up @@ -38,8 +40,12 @@ - (ServiceStatus)checkServiceStatus:(PermissionGroup)permission {
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
PermissionStatus status = [self checkPermissionStatus:permission];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse && permission == PermissionGroupLocationAlways) {
// don't do anything and continue requesting permissions
} else if (status != PermissionStatusDenied) {
BOOL alreadyRequested = [[NSUserDefaults standardUserDefaults] boolForKey:UserDefaultPermissionRequestedKey]; // check if already requested the permantent permission
if(alreadyRequested) {
completionHandler(status);
return;
}
} else if (status != PermissionStatusDenied) { // handles undetermined always permission and denied whenInUse permission
completionHandler(status);
return;
}
Expand All @@ -59,6 +65,7 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveActivityNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
[_locationManager requestAlwaysAuthorization];
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:UserDefaultPermissionRequestedKey];
} 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];
}
Expand Down
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'permission_handler_apple'
s.version = '9.0.2'
s.version = '9.0.4'
s.summary = 'Permission plugin for Flutter.'
s.description = <<-DESC
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
Expand Down
2 changes: 1 addition & 1 deletion permission_handler_apple/pubspec.yaml
@@ -1,6 +1,6 @@
name: permission_handler_apple
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

environment:
Expand Down

0 comments on commit d1b162e

Please sign in to comment.