Skip to content

Commit

Permalink
Remove previously scheduled NetInfo callbacks if they haven't fired
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed Oct 18, 2018
1 parent 61346d3 commit 67afaef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Libraries/Network/RCTNetInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ - (void)dealloc
if (_firstTimeReachability) {
SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
CFRelease(self->_firstTimeReachability);
_firstTimeReachability = nil;
_resolve = nil;
}
}

Expand Down Expand Up @@ -184,6 +186,12 @@ - (BOOL)setReachabilityStatus:(SCNetworkReachabilityFlags)flags
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;
}
Expand Down

0 comments on commit 67afaef

Please sign in to comment.