From 77500e689f3e356e93154bcf893b5e9d8fbbf415 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Fri, 22 Jan 2016 19:16:49 -0500 Subject: [PATCH] [ios] Avoid the blue background location status bar Apps with `whenInUse` location permission will show a blue status bar when they continue to use location services after leaving the foreground. This is worrying and to be avoided, so let's disable telemetry location services in this situation. Fixes #2945 --- CHANGELOG.md | 1 + platform/ios/src/MGLMapboxEvents.m | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6f03a3d173..900a4d3dec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Known issues: - Made telemetry on/off setting available in-app. ([#3445](https://github.com/mapbox/mapbox-gl-native/pull/3445)) - Fixed an issue with users not being counted by Mapbox if they had disabled telemetry. ([#3495](https://github.com/mapbox/mapbox-gl-native/pull/3495)) - Fixed crash caused by MGLAnnotationImage with non-integer width or height ([#2198](https://github.com/mapbox/mapbox-gl-native/issues/2198)) +- No longer triggers blue background location status bar when user has granted "when in use" permission. ([#3671](https://github.com/mapbox/mapbox-gl-native/issues/3671)) ## iOS 3.0.1 diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m index 6654cc6ac52..81f0fb8a9f8 100644 --- a/platform/ios/src/MGLMapboxEvents.m +++ b/platform/ios/src/MGLMapboxEvents.m @@ -336,13 +336,24 @@ - (void)validateUpdatingLocation { if (self.paused) { [self stopUpdatingLocation]; } else { - CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus]; - if (authStatus == kCLAuthorizationStatusDenied || - authStatus == kCLAuthorizationStatusRestricted) { - [self stopUpdatingLocation]; - } else if (authStatus == kCLAuthorizationStatusAuthorized || - authStatus == kCLAuthorizationStatusAuthorizedWhenInUse) { - [self startUpdatingLocation]; + switch ([CLLocationManager authorizationStatus]) { + case kCLAuthorizationStatusNotDetermined: + case kCLAuthorizationStatusRestricted: + case kCLAuthorizationStatusDenied: + [self stopUpdatingLocation]; + break; + case kCLAuthorizationStatusAuthorized: + // Also handles kCLAuthorizationStatusAuthorizedAlways + [self startUpdatingLocation]; + break; + case kCLAuthorizationStatusAuthorizedWhenInUse: + if (UIApplication.sharedApplication.applicationState == UIApplicationStateBackground) { + // Prevent blue status bar when app is not in foreground + [self stopUpdatingLocation]; + } else { + [self startUpdatingLocation]; + } + break; } } }