From a7f06366d2c431bdf34fcfa14314be43ac09987b Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Fri, 25 Aug 2017 18:06:39 -0400 Subject: [ios] Support iOS 11 location usage descriptions --- platform/ios/CHANGELOG.md | 1 + platform/ios/app/Info.plist | 6 ++++-- platform/ios/src/MGLMapView.mm | 26 +++++++++++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index c17a73b059..d8267092df 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ## 3.6.3 * Fixed an issue where user heading tracking mode would update too frequently. ([#9845](https://github.com/mapbox/mapbox-gl-native/pull/9845)) +* Added support for iOS 11 location usage descriptions. ([#9869](https://github.com/mapbox/mapbox-gl-native/pull/9869)) ## 3.6.2 - August 18, 2017 diff --git a/platform/ios/app/Info.plist b/platform/ios/app/Info.plist index 167e66fa09..a98a8c10c5 100644 --- a/platform/ios/app/Info.plist +++ b/platform/ios/app/Info.plist @@ -27,9 +27,11 @@ NSHumanReadableCopyright © 2014–2017 Mapbox NSLocationAlwaysUsageDescription - The map will ALWAYS display the user’s location. + The map will display your location. The map may also use your location when it isn’t visible in order to improve OpenStreetMap and Mapbox products. NSLocationWhenInUseUsageDescription - The map will display the user’s location. + The map will display your location. + NSLocationAlwaysAndWhenInUseUsageDescription + The map will display your location. If you choose Always, the map may also use your location when it isn’t visible in order to improve OpenStreetMap and Mapbox products. UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 18a8d2608a..af7122fc14 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -4160,23 +4160,35 @@ public: { self.locationManager = [[CLLocationManager alloc] init]; - if ([CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) + if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) { - BOOL hasLocationDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] || [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]; - if (!hasLocationDescription) + BOOL requiresWhenInUseUsageDescription = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){11,0,0}]; + BOOL hasWhenInUseUsageDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]; + BOOL hasAlwaysUsageDescription; + if (requiresWhenInUseUsageDescription) { - [NSException raise:@"Missing Location Services usage description" format: - @"This app must have a value for NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in its Info.plist."]; + hasAlwaysUsageDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"] && hasWhenInUseUsageDescription; + } + else + { + hasAlwaysUsageDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]; } - if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) + if (hasAlwaysUsageDescription) { [self.locationManager requestAlwaysAuthorization]; } - else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) + else if (hasWhenInUseUsageDescription) { [self.locationManager requestWhenInUseAuthorization]; } + else + { + NSString *suggestedUsageKeys = requiresWhenInUseUsageDescription ? + @"NSLocationWhenInUseUsageDescription and (optionally) NSLocationAlwaysAndWhenInUseUsageDescription" : + @"NSLocationWhenInUseUsageDescription and/or NSLocationAlwaysUsageDescription"; + [NSException raise:@"Missing Location Services usage description" format:@"This app must have a value for %@ in its Info.plist.", suggestedUsageKeys]; + } } self.locationManager.headingFilter = 5.0; -- cgit v1.2.1