diff --git a/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m b/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m index ca513cd..11ae991 100644 --- a/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +++ b/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m @@ -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