diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-04-18 23:13:42 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-04-18 23:13:42 -0700 |
commit | d76ef6e53b56d163df823e7970e18cafd402bbb3 (patch) | |
tree | 207bb7de6cfedbabbadfdc646306cd011e2b3bfd /platform/ios | |
parent | b519ee908b92ec9b8b9aa00653833fa7f79e6321 (diff) | |
download | qtlocation-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')
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapboxEvents.m | 18 |
2 files changed, 7 insertions, 12 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 37314ba784..b6734a0fd9 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -9,6 +9,7 @@ Mapbox welcomes participation and contributions from everyone. If you’d like - The user dot now moves smoothly between user location updates while user location tracking is disabled. ([#1582](https://github.com/mapbox/mapbox-gl-native/pull/1582)) - User location heading updates now resume properly when an app becomes active again. ([#4674](https://github.com/mapbox/mapbox-gl-native/pull/4674)) - Fixed an issue preventing KVO change notifications from being generated on MGLMapView’s `userTrackingMode` key path when `-setUserTrackingMode:animated:` is called. ([#4724](https://github.com/mapbox/mapbox-gl-native/pull/4724)) +- 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)) - Added a `-reloadStyle:` action to MGLMapView to force a reload of the current style. ([#4728](https://github.com/mapbox/mapbox-gl-native/pull/4728)) - A more specific user agent string is now sent with style and tile requests. ([#4012](https://github.com/mapbox/mapbox-gl-native/pull/4012)) - Mapbox Telemetry is automatically disabled while the host application is running in the iOS Simulator. ([#4726](https://github.com/mapbox/mapbox-gl-native/pull/4726)) 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 && |