[ios] Support iOS 11 location usage descriptions

This commit is contained in:
Jason Wray
2017-08-25 18:06:39 -04:00
parent 5cad92cc33
commit a7f06366d2
3 changed files with 24 additions and 9 deletions

View File

@@ -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

View File

@@ -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>

View File

@@ -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;