mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove previously scheduled NetInfo callbacks if they haven't fired
Summary: @public If you call NetInfo.getCurrentConnectivity multiple times in succession, we'll create a bunch of callbacks but lose them in the ether. With this fix, we'll unschedule them before creating a new one, which should resolve some crashes we're seeing. Reviewed By: PeteTheHeat Differential Revision: D10409486 fbshipit-source-id: 6065b09fa626f7f06aed9bf0e278c0a6a6169f58
This commit is contained in:
committed by
Lorenzo Sciandra
parent
4420e391ab
commit
03bc46d411
@@ -110,6 +110,8 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC
|
||||
if (_firstTimeReachability) {
|
||||
SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
|
||||
CFRelease(self->_firstTimeReachability);
|
||||
_firstTimeReachability = nil;
|
||||
_resolve = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +186,12 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC
|
||||
RCT_EXPORT_METHOD(getCurrentConnectivity:(RCTPromiseResolveBlock)resolve
|
||||
reject:(__unused RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
if (_firstTimeReachability) {
|
||||
SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
|
||||
CFRelease(self->_firstTimeReachability);
|
||||
_firstTimeReachability = nil;
|
||||
_resolve = nil;
|
||||
}
|
||||
_firstTimeReachability = [self getReachabilityRef];
|
||||
_resolve = resolve;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user