diff options
author | Jason Wray <friedbunny@users.noreply.github.com> | 2019-09-09 17:25:42 -0700 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2019-09-11 19:46:05 -0700 |
commit | ec0eabb528369c32d0c658636ff0497317017218 (patch) | |
tree | a227b84cf8f38f6a7278955851d2d5724366afc3 | |
parent | 672b3cb744bb4eb063a0a7ec6914311607015418 (diff) | |
download | qtlocation-mapboxgl-upstream/friedbunny-ios-v5.3.1-ios-13-cherry-picks.tar.gz |
[ios] Refactor way location permissions are requestedupstream/friedbunny-ios-v5.3.1-ios-13-cherry-picks
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 51102233cf..502c811fbb 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -5291,35 +5291,29 @@ public: if (shouldEnableLocationServices) { - if (self.locationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined) - { - BOOL requiresWhenInUseUsageDescription = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){11,0,0}]; + if (self.locationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined) { BOOL hasWhenInUseUsageDescription = !![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]; - BOOL hasAlwaysUsageDescription; - if (requiresWhenInUseUsageDescription) - { - hasAlwaysUsageDescription = !![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"] && hasWhenInUseUsageDescription; - } - else - { - hasAlwaysUsageDescription = !![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]; - } - if (hasAlwaysUsageDescription) - { - [self.locationManager requestAlwaysAuthorization]; - } - else if (hasWhenInUseUsageDescription) - { - [self.locationManager requestWhenInUseAuthorization]; - } - else - { - NSString *suggestedUsageKeys = requiresWhenInUseUsageDescription ? - @"NSLocationWhenInUseUsageDescription and (optionally) NSLocationAlwaysAndWhenInUseUsageDescription" : - @"NSLocationWhenInUseUsageDescription and/or NSLocationAlwaysUsageDescription"; - [NSException raise:MGLMissingLocationServicesUsageDescriptionException - format:@"This app must have a value for %@ in its Info.plist.", suggestedUsageKeys]; + if (@available(iOS 11.0, *)) { + // A WhenInUse string is required in iOS 11+ and the map never has any need for Always, so it's enough to just ask for WhenInUse. + if (hasWhenInUseUsageDescription) { + [self.locationManager requestWhenInUseAuthorization]; + } else { + [NSException raise:MGLMissingLocationServicesUsageDescriptionException + format:@"To use location services this app must have a NSLocationWhenInUseUsageDescription string in its Info.plist."]; + } + } else { + // We might have to ask for Always if the app does not provide a WhenInUse string. + BOOL hasAlwaysUsageDescription = !![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]; + + if (hasWhenInUseUsageDescription) { + [self.locationManager requestWhenInUseAuthorization]; + } else if (hasAlwaysUsageDescription) { + [self.locationManager requestAlwaysAuthorization]; + } else { + [NSException raise:MGLMissingLocationServicesUsageDescriptionException + format:@"To use location services this app must have a NSLocationWhenInUseUsageDescription and/or NSLocationAlwaysUsageDescription string in its Info.plist."]; + } } } |