diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 68049be4c..d038fafe2 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 13540bfd0..930095351 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 &&