Skip to content

Commit 2a76ca6

Browse files
committed
[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 <unknown> index.ios.bundle:7656 <unknown> index.ios.bundle:7648 perform index.ios.bundle:6157 batchedUpdates index.ios.bundle:13786 batchedUpdates index.ios.bundle:4689 <unknown> 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 facebook/react-native#1226 Github Author: henter <henter@henter.me> Test Plan: Imported from GitHub, without a `Test Plan:` line.
1 parent 769efdf commit 2a76ca6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Libraries/Geolocation/RCTLocationObserver.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ @implementation RCTLocationRequest
8585

8686
- (void)dealloc
8787
{
88-
[_timeoutTimer invalidate];
88+
if (_timeoutTimer.valid) {
89+
[_timeoutTimer invalidate];
90+
}
8991
}
9092

9193
@end
@@ -273,6 +275,7 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray
273275
// Fire all queued callbacks
274276
for (RCTLocationRequest *request in _pendingRequests) {
275277
request.successBlock(@[_lastLocationEvent]);
278+
[request.timeoutTimer invalidate];
276279
}
277280
[_pendingRequests removeAllObjects];
278281

@@ -311,6 +314,7 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
311314
// Fire all queued error callbacks
312315
for (RCTLocationRequest *request in _pendingRequests) {
313316
request.errorBlock(@[jsError]);
317+
[request.timeoutTimer invalidate];
314318
}
315319
[_pendingRequests removeAllObjects];
316320

0 commit comments

Comments
 (0)