summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2017-07-21 10:29:49 -0700
committerJesse Bounds <jesse@rebounds.net>2017-07-21 10:29:49 -0700
commitfb2df21037795589d71489c64a5e17cbcb5f1254 (patch)
treefb0c196ba0592dcbc5328a082e94d49970484698
parent7aad3613c3549ae5f4388fcbeef969e13274892b (diff)
downloadqtlocation-mapboxgl-upstream/boundsj-add-bg-location-option.tar.gz
[ios] Add option to disable background location updatesupstream/boundsj-add-bg-location-option
-rw-r--r--platform/ios/src/MGLLocationManager.h1
-rw-r--r--platform/ios/src/MGLLocationManager.m10
-rw-r--r--platform/ios/src/MGLMapboxEvents.m4
3 files changed, 13 insertions, 2 deletions
diff --git a/platform/ios/src/MGLLocationManager.h b/platform/ios/src/MGLLocationManager.h
index ea23801813..65d2ee9b84 100644
--- a/platform/ios/src/MGLLocationManager.h
+++ b/platform/ios/src/MGLLocationManager.h
@@ -6,6 +6,7 @@
@interface MGLLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic, weak) id<MGLLocationManagerDelegate> delegate;
+@property (nonatomic) BOOL allowsBackgroundLocationUpdates;
- (void)startUpdatingLocation;
- (void)stopUpdatingLocation;
diff --git a/platform/ios/src/MGLLocationManager.m b/platform/ios/src/MGLLocationManager.m
index b0d2e17d5d..f1a109876d 100644
--- a/platform/ios/src/MGLLocationManager.m
+++ b/platform/ios/src/MGLLocationManager.m
@@ -23,7 +23,8 @@ static NSString * const MGLLocationManagerRegionIdentifier = @"MGLLocationManage
self = [super init];
if (self) {
NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
- _hostAppHasBackgroundCapability = [backgroundModes containsObject:@"location"];
+ _hostAppHasBackgroundCapability = [backgroundModes containsObject:@"location"];
+ _allowsBackgroundLocationUpdates = YES;
}
return self;
}
@@ -55,6 +56,11 @@ static NSString * const MGLLocationManagerRegionIdentifier = @"MGLLocationManage
}
}
+- (void)setAllowsBackgroundLocationUpdates:(BOOL)allowsBackgroundLocationUpdates {
+ _allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates;
+ self.standardLocationManager.allowsBackgroundLocationUpdates = _allowsBackgroundLocationUpdates;
+}
+
#pragma mark - Utilities
- (void)configurePassiveStandardLocationManager {
@@ -82,7 +88,7 @@ static NSString * const MGLLocationManagerRegionIdentifier = @"MGLLocationManage
[self startBackgroundTimeoutTimer];
// On iOS 9 and above also allow background location updates
if ([self.standardLocationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
- self.standardLocationManager.allowsBackgroundLocationUpdates = YES;
+ self.standardLocationManager.allowsBackgroundLocationUpdates = _allowsBackgroundLocationUpdates;
}
}
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 4f1413d300..e31fdf3515 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -140,6 +140,7 @@ const NSTimeInterval MGLFlushInterval = 180;
@"MGLMapboxAccountType": accountTypeNumber ?: @0,
@"MGLMapboxMetricsEnabled": @YES,
@"MGLMapboxMetricsDebugLoggingEnabled": @NO,
+ @"MGLMapboxMetricsAllowsBackgroundLocationUpdates": @YES,
}];
}
}
@@ -272,6 +273,9 @@ const NSTimeInterval MGLFlushInterval = 180;
[self pauseMetricsCollection];
return;
}
+
+ BOOL allowsBackgroundLocationUpdates = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsAllowsBackgroundLocationUpdates"];
+ self.locationManager.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates;
// Toggle pause based on current pause state, user opt-out state, and low-power state.
BOOL enabled = [[self class] isEnabled];