From 84c9154dd847fb6f23e9174e5ae89fd1b6988825 Mon Sep 17 00:00:00 2001 From: Jean-Richard Lai Date: Thu, 14 Apr 2016 21:29:47 -0700 Subject: [PATCH] Fix distanceFilter caching for LocationObserver Allow changing distanceFilter after _locationManager has been initialized. --- Libraries/Geolocation/RCTLocationObserver.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Libraries/Geolocation/RCTLocationObserver.m b/Libraries/Geolocation/RCTLocationObserver.m index f2e76f3612f97b..85f4e86b2bae50 100644 --- a/Libraries/Geolocation/RCTLocationObserver.m +++ b/Libraries/Geolocation/RCTLocationObserver.m @@ -130,11 +130,11 @@ - (dispatch_queue_t)methodQueue #pragma mark - Private API -- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy + +- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter { if (!_locationManager) { _locationManager = [CLLocationManager new]; - _locationManager.distanceFilter = _observerOptions.distanceFilter; _locationManager.delegate = self; } @@ -147,6 +147,7 @@ - (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccur [_locationManager requestWhenInUseAuthorization]; } + _locationManager.distanceFilter = distanceFilter; _locationManager.desiredAccuracy = desiredAccuracy; // Start observing location [_locationManager startUpdatingLocation]; @@ -179,7 +180,7 @@ - (void)timeout:(NSTimer *)timer _observerOptions.accuracy = MIN(_observerOptions.accuracy, request.options.accuracy); } - [self beginLocationUpdatesWithDesiredAccuracy:_observerOptions.accuracy]; + [self beginLocationUpdatesWithDesiredAccuracy:_observerOptions.accuracy distanceFilter:_observerOptions.distanceFilter]; _observingLocation = YES; } @@ -253,7 +254,7 @@ - (void)timeout:(NSTimer *)timer if (_locationManager) { accuracy = MIN(_locationManager.desiredAccuracy, accuracy); } - [self beginLocationUpdatesWithDesiredAccuracy:accuracy]; + [self beginLocationUpdatesWithDesiredAccuracy:accuracy distanceFilter:options.distanceFilter]; } #pragma mark - CLLocationManagerDelegate