diff options
author | Jason Wray <jason@mapbox.com> | 2017-08-25 18:06:39 -0400 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2017-08-28 12:15:11 -0400 |
commit | a7f06366d2c431bdf34fcfa14314be43ac09987b (patch) | |
tree | d9b25c378aea2ac5d5ea7296719c1abf96369e2c | |
parent | 5cad92cc336768a93875865c6d4abbfe10c13bd1 (diff) | |
download | qtlocation-mapboxgl-a7f06366d2c431bdf34fcfa14314be43ac09987b.tar.gz |
[ios] Support iOS 11 location usage descriptions
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/app/Info.plist | 6 | ||||
-rw-r--r-- | 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 @@ <key>NSHumanReadableCopyright</key> <string>© 2014–2017 Mapbox</string> <key>NSLocationAlwaysUsageDescription</key> - <string>The map will ALWAYS display the user’s location.</string> + <string>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.</string> <key>NSLocationWhenInUseUsageDescription</key> - <string>The map will display the user’s location.</string> + <string>The map will display your location.</string> + <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> + <string>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.</string> <key>UILaunchStoryboardName</key> <string>LaunchScreen</string> <key>UIMainStoryboardFile</key> 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; |