[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 d76ef6e53b.
This commit is contained in:
Minh Nguyễn
2016-04-18 23:13:42 -07:00
committed by Minh Nguyễn
parent b8ecbf6b35
commit e5fa7093da
2 changed files with 10 additions and 12 deletions

View File

@@ -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))

View File

@@ -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 &&