Skip to content

Commit 67afaef

Browse files
Mehdi Mulanifacebook-github-bot
authored andcommitted
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
1 parent 61346d3 commit 67afaef

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Libraries/Network/RCTNetInfo.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ - (void)dealloc
110110
if (_firstTimeReachability) {
111111
SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
112112
CFRelease(self->_firstTimeReachability);
113+
_firstTimeReachability = nil;
114+
_resolve = nil;
113115
}
114116
}
115117

@@ -184,6 +186,12 @@ - (BOOL)setReachabilityStatus:(SCNetworkReachabilityFlags)flags
184186
RCT_EXPORT_METHOD(getCurrentConnectivity:(RCTPromiseResolveBlock)resolve
185187
reject:(__unused RCTPromiseRejectBlock)reject)
186188
{
189+
if (_firstTimeReachability) {
190+
SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
191+
CFRelease(self->_firstTimeReachability);
192+
_firstTimeReachability = nil;
193+
_resolve = nil;
194+
}
187195
_firstTimeReachability = [self getReachabilityRef];
188196
_resolve = resolve;
189197
}

0 commit comments

Comments
 (0)