summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2019-09-06 13:27:34 -0700
committerJason Wray <jason@mapbox.com>2019-09-06 14:15:48 -0700
commitea4900d601dd9ac022481e17ae46ab6bcbde28b5 (patch)
tree6d5a50da7fd94cbc7e6b0c79eab1e69871755f55
parentb391679799cff8145cf44a06500cfe0ebe9d8168 (diff)
downloadqtlocation-mapboxgl-upstream/friedbunny-asks-for-fewer-location-permissions.tar.gz
[ios] Refactor way location permissions are requestedupstream/friedbunny-asks-for-fewer-location-permissions
-rw-r--r--platform/ios/src/MGLMapView.mm48
1 files changed, 21 insertions, 27 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 2e96931a63..62b943fd3d 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -5303,35 +5303,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."];
+ }
}
}