From 2a76ca635e6524498bf10d72cf6bfe028e0a4b2c Mon Sep 17 00:00:00 2001 From: henter Date: Tue, 26 May 2015 14:54:32 -0700 Subject: [PATCH] [GeoLocation] invalidate timer after success or error callback Summary: Just trying to [getCurrentPosition](https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/Geolocation.js#L45) , and found the `errorBlock` of location request in timeout handler would cause red error like this: ``` 2015-05-10 17:50:39.607 [warn][tid:com.facebook.React.JavaScript] "Warning: Cannot find callback with CBID 5. Native module may have invoked both the success callback and the error callback." 2015-05-10 17:50:39.610 [error][tid:com.facebook.React.JavaScript] "Error: null is not an object (evaluating 'cb.apply') stack: _invokeCallback index.ios.bundle:7593 index.ios.bundle:7656 index.ios.bundle:7648 perform index.ios.bundle:6157 batchedUpdates index.ios.bundle:13786 batchedUpdates index.ios.bundle:4689 index.ios.bundle:7647 applyWithGuard index.ios.bundle:882 guardReturn index.ios.bundle:7421 processBatch index.ios.bundle:7646 URL: http://192.168.100.182:8081/index Closes https://github.com/facebook/react-native/pull/1226 Github Author: henter Test Plan: Imported from GitHub, without a `Test Plan:` line. --- Libraries/Geolocation/RCTLocationObserver.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/Geolocation/RCTLocationObserver.m b/Libraries/Geolocation/RCTLocationObserver.m index f21233dbf..0fe5fed75 100644 --- a/Libraries/Geolocation/RCTLocationObserver.m +++ b/Libraries/Geolocation/RCTLocationObserver.m @@ -85,7 +85,9 @@ static NSDictionary *RCTPositionError(RCTPositionErrorCode code, NSString *msg / - (void)dealloc { - [_timeoutTimer invalidate]; + if (_timeoutTimer.valid) { + [_timeoutTimer invalidate]; + } } @end @@ -273,6 +275,7 @@ RCT_EXPORT_METHOD(getCurrentPosition:(RCTLocationOptions)options // Fire all queued callbacks for (RCTLocationRequest *request in _pendingRequests) { request.successBlock(@[_lastLocationEvent]); + [request.timeoutTimer invalidate]; } [_pendingRequests removeAllObjects]; @@ -311,6 +314,7 @@ RCT_EXPORT_METHOD(getCurrentPosition:(RCTLocationOptions)options // Fire all queued error callbacks for (RCTLocationRequest *request in _pendingRequests) { request.errorBlock(@[jsError]); + [request.timeoutTimer invalidate]; } [_pendingRequests removeAllObjects];