Skip to content

Commit

Permalink
fix location manager initiated on non main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mauron85 committed May 28, 2018
1 parent 60a9647 commit 0435a0b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions BackgroundGeolocation/MAURBackgroundGeolocationFacade.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,21 @@ - (MAURLocation*)getCurrentLocation:(int)timeout maximumAge:(long)maximumAge
enableHighAccuracy:(BOOL)enableHighAccuracy
error:(NSError * __autoreleasing *)outError
{
CLLocation *currentLocation = [MAURLocationManager sharedInstance].locationManager.location;
if (currentLocation != nil) {
long locationAge = ceil(fabs([currentLocation.timestamp timeIntervalSinceNow]) * 1000);
if (locationAge <= maximumAge) {
return [MAURLocation fromCLLocation:currentLocation];
}
}

__block NSError *error = nil;
__block CLLocation *location = nil;

dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[self runOnMainThread:^{
CLLocation *currentLocation = [MAURLocationManager sharedInstance].locationManager.location;
if (currentLocation != nil) {
long locationAge = ceil(fabs([currentLocation.timestamp timeIntervalSinceNow]) * 1000);
if (locationAge <= maximumAge) {
location = currentLocation;
dispatch_semaphore_signal(sema);
return;
}
}

INTULocationManager *locationManager = [INTULocationManager sharedInstance];
float timeoutInSeconds = ceil((float)timeout/1000);
[locationManager requestLocationWithDesiredAccuracy:enableHighAccuracy ? INTULocationAccuracyRoom : INTULocationAccuracyCity
Expand Down

0 comments on commit 0435a0b

Please sign in to comment.