[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 https://github.com/facebook/react-native/pull/1226 Github Author: henter <henter@henter.me> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
parent
769efdfcef
commit
2a76ca635e
|
@ -85,8 +85,10 @@ static NSDictionary *RCTPositionError(RCTPositionErrorCode code, NSString *msg /
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
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];
|
||||
|
||||
|
|
Loading…
Reference in New Issue