Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Request JIT accuracy #392

Merged
merged 4 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added `[MGLLocationManagerDelegate locationManagerDidChangeAuthorization:]` to let `MGLMapView` know about privacy changes. ([#376](https://github.com/mapbox/mapbox-gl-native-ios/pull/376))
* Added `[MGLMapViewDelegate mapView:didChangeLocationManagerAuthorization:]` to allow developers adjust their apps to privacy settings changes. ([#376](https://github.com/mapbox/mapbox-gl-native-ios/pull/376))
* Added an approximate user location halo when `MGLLocationManager.accuracyAuthorization` is set to `CLAccuracyAuthorizationReducedAccuracy`. ([#381](https://github.com/mapbox/mapbox-gl-native-ios/pull/381))
* The `MGLAccuracyAuthorizationDescription` as element of `NSLocationTemporaryUsageDescriptionDictionary` Info.plist key can now be set to describe why you request accuracy authorization. ([#392](https://github.com/mapbox/mapbox-gl-native-ios/pull/392))

## 6.1.0

Expand Down
2 changes: 1 addition & 1 deletion platform/ios/app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<true/>
<key>NSLocationTemporaryUsageDescriptionDictionary</key>
<dict>
<key>MBXRequestAccuracy</key>
<key>MGLAccuracyAuthorizationDescription</key>
<string>Mapbox requires your precise location to help you navigate the map.</string>
</dict>
<key>NSHumanReadableCopyright</key>
Expand Down
23 changes: 2 additions & 21 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1972,18 +1972,6 @@ - (IBAction)cycleStyles:(__unused id)sender

- (IBAction)locateUser:(id)sender
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
if (@available(iOS 14, *)) {
if (self.mapView.locationManager.accuracyAuthorization == CLAccuracyAuthorizationReducedAccuracy) {
[self.mapView.locationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKey:@"MBXRequestAccuracy"];
__weak MBXViewController *weakSelf = self;
self.locationBlock = ^{
[weakSelf nextTrackingMode:sender];
};
return;
}
}
#endif
[self nextTrackingMode:sender];
}

Expand Down Expand Up @@ -2373,10 +2361,6 @@ - (void)mapView:(nonnull MGLMapView *)mapView didChangeLocationManagerAuthorizat
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
if (manager.authorizationStatus == kCLAuthorizationStatusDenied || manager.accuracyAuthorization == CLAccuracyAuthorizationReducedAccuracy) {
[self alertAccuracyChanges];
} else {
if (self.locationBlock) {
self.locationBlock();
}
}
#endif
}
Expand All @@ -2390,12 +2374,9 @@ - (void)alertAccuracyChanges {
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"Turn On in Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
__weak MBXViewController *weakSelf = self;

UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Keep Precise Location Off" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
weakSelf.mapView.userTrackingMode = MGLUserTrackingModeNone;
weakSelf.mapView.showsUserLocation = NO;
}];
handler:nil];
[alert addAction:settingsAction];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
Expand Down
15 changes: 15 additions & 0 deletions platform/ios/docs/guides/Info.plist Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ Mapbox-hosted vector tiles and styles require an API access token, which you can

As an alternative, you can use `MGLAccountManager.accessToken` to set a token in code. See [our guide](https://www.mapbox.com/help/ios-private-access-token/) for some tips on keeping access tokens in open source code private.

## MGLAccuracyAuthorizationDescription

Set the Mapbox accuracy authorization description string as an element of `NSLocationTemporaryUsageDescriptionDictionary` to be used by the map to request authorization when the `MGLLocationManager.accuracyAuthorization` is set to `CLAccuracyAuthorizationReducedAccuracy`. Requesting accuracy authorization is available for devices running iOS 14.0 and above.

Example:
```
<key>NSLocationTemporaryUsageDescriptionDictionary</key>
<dict>
<key>MGLAccuracyAuthorizationDescription</key>
<string>Mapbox requires your precise location to help you navigate the map.</string>
</dict>
```

Remove `MGLAccuracyAuthorizationDescription` if you want to control when to request for accuracy authorization.

## MGLMapboxAPIBaseURL

Use this key if you need to customize the API base URL used throughout the SDK. If unset, the default Mapbox API is used.
Expand Down
21 changes: 20 additions & 1 deletion platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5532,6 +5532,11 @@ - (void)validateLocationServices
}
}

- (NSString *)accuracyDescriptionString {
NSDictionary *dictionary = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationTemporaryUsageDescriptionDictionary"];
return dictionary[@"MGLAccuracyAuthorizationDescription"];
}

- (void)setShowsUserLocation:(BOOL)showsUserLocation
{
MGLLogDebug(@"Setting showsUserLocation: %@", MGLStringFromBOOL(showsUserLocation));
Expand Down Expand Up @@ -6098,7 +6103,21 @@ - (void)locationManagerDidChangeAuthorization:(id<MGLLocationManager>)manager
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingHeading];
} else {
[self validateLocationServices];
if (@available(iOS 14, *)) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
if ((manager.authorizationStatus != kCLAuthorizationStatusRestricted ||
manager.authorizationStatus != kCLAuthorizationStatusAuthorizedAlways ||
manager.authorizationStatus != kCLAuthorizationStatusAuthorizedWhenInUse) &&
manager.accuracyAuthorization == CLAccuracyAuthorizationReducedAccuracy &&
[self accuracyDescriptionString] != nil ) {
[self.locationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKey:@"MGLAccuracyAuthorizationDescription"];
} else {
[self validateLocationServices];
}
#endif
} else {
[self validateLocationServices];
}
}

if (@available(iOS 14, *)) {
Expand Down