summaryrefslogtreecommitdiff
path: root/platform
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-20 14:43:45 -0700
commite5fa7093daf8d93800a06e6ce39c451ea8943e30 (patch)
tree3b59611baaf5a8811162bf983bfd60a64fbef14e /platform
parentb8ecbf6b357a20ffd0b9d40c7425aac2a7b5d409 (diff)
downloadqtlocation-mapboxgl-e5fa7093daf8d93800a06e6ce39c451ea8943e30.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. Cherry-picked from d76ef6e53b56d163df823e7970e18cafd402bbb3.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/CHANGELOG.md4
-rw-r--r--platform/ios/src/MGLMapboxEvents.m18
2 files changed, 10 insertions, 12 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index 68049be4cc..d038fafe27 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -2,6 +2,10 @@
Mapbox welcomes participation and contributions from everyone. If you’d like to do so please see [CONTRIBUTING.md](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started.
+## 3.2.1
+
+- Fixed a hang that could occur if the host application attempts to set user defaults on a background queue. ([#4745](https://github.com/mapbox/mapbox-gl-native/pull/4745))
+
## 3.2.0
- If you’ve previously installed the SDK as a static framework, the installation workflow has changed to address issues when submitting your application to the App Store or installing it on a device. Upon upgrading to this version of the SDK, you’ll need to add Mapbox.bundle to the Copy Bundle Resources build phase and remove Mapbox.framework from the Embed Frameworks build phase. ([#4455](https://github.com/mapbox/mapbox-gl-native/pull/4455))
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 13540bfd08..9300953519 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;
}
@@ -195,17 +194,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];
@@ -229,7 +219,7 @@ const NSTimeInterval MGLFlushInterval = 180;
}
- (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:_userDefaultsObserver];
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[self pauseMetricsCollection];
}
@@ -245,6 +235,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 &&