Skip to content

Commit

Permalink
Make locationManager initialization thread safe
Browse files Browse the repository at this point in the history
Fixes #316

Also it turns out that this property is readonly, so I made it readonly.
  • Loading branch information
S2Ler committed Sep 28, 2021
1 parent cfa9648 commit 900e108
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions Sources/MapboxMobileEvents/MMELocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@interface MMELocationManager () <CLLocationManagerDelegate>

@property (nonatomic) id<MMEUIApplicationWrapper> application;
@property (nonatomic) CLLocationManager *locationManager;
@property (nonatomic, readonly) CLLocationManager *locationManager;
@property (nonatomic, getter=isUpdatingLocation, readwrite) BOOL updatingLocation;
@property (nonatomic) NSDate *backgroundLocationServiceTimeoutAllowedDate;
@property (nonatomic) NSTimer *backgroundLocationServiceTimeoutTimer;
Expand All @@ -31,16 +31,15 @@ @interface MMELocationManager () <CLLocationManagerDelegate>

@implementation MMELocationManager

@synthesize locationManager = _locationManager;

- (void)dealloc {
_locationManager.delegate = nil;
}

- (CLLocationManager *)locationManager {
if (_locationManager == nil) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_locationManager = [[MMEDependencyManager sharedManager] locationManagerInstance];
}
});
return _locationManager;
}

Expand Down Expand Up @@ -110,17 +109,6 @@ - (NSString *)accuracyAuthorizationString {
}
#endif

- (void)setLocationManager:(CLLocationManager *)locationManager {
if (locationManager == nil) {
_locationManager = locationManager;
} else {
id<CLLocationManagerDelegate> delegate = _locationManager.delegate;
_locationManager.delegate = nil;
_locationManager = locationManager;
_locationManager.delegate = delegate;
}
}

- (void)stopMonitoringRegions {
for(CLRegion *region in self.locationManager.monitoredRegions) {
if([region.identifier isEqualToString:MMELocationManagerRegionIdentifier]) {
Expand Down

0 comments on commit 900e108

Please sign in to comment.