summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2016-06-15 23:48:18 -0700
committerJason Wray <jason@mapbox.com>2016-06-20 14:06:54 -0400
commita7d5717cf5a5adb6d2bb5641c81c97c46965b8fa (patch)
treec1f0ec638ff968995240025168daec6c99c86968
parent061854990ffe495910a5f0dc7c6bb5d394f772e9 (diff)
downloadqtlocation-mapboxgl-a7d5717cf5a5adb6d2bb5641c81c97c46965b8fa.tar.gz
[ios] Disable telemetry while Low Power Mode is enabled
Low Power Mode is iOS 9+, so some availability checks must be made.
-rw-r--r--platform/ios/src/MGLMapboxEvents.m24
1 files changed, 17 insertions, 7 deletions
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 5ddf4e2b57..53b917f701 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -147,11 +147,17 @@ const NSTimeInterval MGLFlushInterval = 180;
#if TARGET_OS_SIMULATOR
return NO;
#else
+ BOOL isLowPowerModeEnabled = NO;
+ if ([NSProcessInfo instancesRespondToSelector:@selector(isLowPowerModeEnabled)]) {
+ isLowPowerModeEnabled = [[NSProcessInfo processInfo] isLowPowerModeEnabled];
+ }
return ([[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsEnabled"] &&
- [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0);
+ [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0 &&
+ !isLowPowerModeEnabled);
#endif
}
+
- (BOOL)debugLoggingEnabled {
return (self.canEnableDebugLogging &&
[[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"]);
@@ -203,6 +209,11 @@ const NSTimeInterval MGLFlushInterval = 180;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseOrResumeMetricsCollectionIfRequired) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseOrResumeMetricsCollectionIfRequired) name:UIApplicationWillEnterForegroundNotification object:nil];
+
+ // Watch for Low Power Mode change events
+ if (&NSProcessInfoPowerStateDidChangeNotification != NULL) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseOrResumeMetricsCollectionIfRequired) name:NSProcessInfoPowerStateDidChangeNotification object:nil];
+ }
}
return self;
}
@@ -253,12 +264,11 @@ const NSTimeInterval MGLFlushInterval = 180;
return;
}
- // Toggle pause based on current pause state and current settings state
- // Practically, a pause only occurs because of a change to an NSUserDefaultsDidChangeNotification
- BOOL enabledInSettings = [[self class] isEnabled];
- if (self.paused && enabledInSettings) {
+ // Toggle pause based on current pause state, user opt-out state, and low-power state.
+ BOOL enabled = [[self class] isEnabled];
+ if (self.paused && enabled) {
[self resumeMetricsCollection];
- } else if (!self.paused && !enabledInSettings) {
+ } else if (!self.paused && !enabled) {
[self pauseMetricsCollection];
}
}
@@ -281,7 +291,7 @@ const NSTimeInterval MGLFlushInterval = 180;
if (!self.paused || ![[self class] isEnabled]) {
return;
}
-
+
self.paused = NO;
self.data = [[MGLMapboxEventsData alloc] init];