summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapboxEvents.m
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-18 23:13:42 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-18 23:13:42 -0700
commitd76ef6e53b56d163df823e7970e18cafd402bbb3 (patch)
tree207bb7de6cfedbabbadfdc646306cd011e2b3bfd /platform/ios/src/MGLMapboxEvents.m
parentb519ee908b92ec9b8b9aa00653833fa7f79e6321 (diff)
downloadqtlocation-mapboxgl-d76ef6e53b56d163df823e7970e18cafd402bbb3.tar.gz
[ios] Fixed hang observing user defaults on background queue
Fixed a deadlock that could occur if the host application attempts to set user defaults on a background queue. Now we observer user defaults changes synchronously.
Diffstat (limited to 'platform/ios/src/MGLMapboxEvents.m')
-rw-r--r--platform/ios/src/MGLMapboxEvents.m18
1 files changed, 6 insertions, 12 deletions
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index ce07c5602d..0967257bfd 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -128,7 +128,6 @@ const NSTimeInterval MGLFlushInterval = 180;
@end
@implementation MGLMapboxEvents {
- id _userDefaultsObserver;
NSString *_instanceID;
}
@@ -199,17 +198,8 @@ const NSTimeInterval MGLFlushInterval = 180;
self.canEnableDebugLogging = YES;
}
-
// Watch for changes to telemetry settings by the user
- __weak MGLMapboxEvents *weakSelf = self;
- _userDefaultsObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSUserDefaultsDidChangeNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:
- ^(NSNotification *notification) {
- MGLMapboxEvents *strongSelf = weakSelf;
- [strongSelf pauseOrResumeMetricsCollectionIfRequired];
- }];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDefaultsDidChange:) name:NSUserDefaultsDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseOrResumeMetricsCollectionIfRequired) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseOrResumeMetricsCollectionIfRequired) name:UIApplicationWillEnterForegroundNotification object:nil];
@@ -233,7 +223,7 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:_userDefaultsObserver];
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[self pauseMetricsCollection];
}
@@ -249,6 +239,10 @@ const NSTimeInterval MGLFlushInterval = 180;
return _instanceID;
}
+- (void)userDefaultsDidChange:(NSNotification *)notification {
+ [self pauseOrResumeMetricsCollectionIfRequired];
+}
+
- (void)pauseOrResumeMetricsCollectionIfRequired {
// Prevent blue status bar when host app has `when in use` permission only and it is not in foreground
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse &&