From 67afaefa78c314b38249a7e2758e0af38c18f34a Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Thu, 18 Oct 2018 12:13:19 -0700 Subject: [PATCH] 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 --- Libraries/Network/RCTNetInfo.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Libraries/Network/RCTNetInfo.m b/Libraries/Network/RCTNetInfo.m index 715bfc3ad92292..9b90c454f5871b 100644 --- a/Libraries/Network/RCTNetInfo.m +++ b/Libraries/Network/RCTNetInfo.m @@ -110,6 +110,8 @@ - (void)dealloc if (_firstTimeReachability) { SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes); CFRelease(self->_firstTimeReachability); + _firstTimeReachability = nil; + _resolve = nil; } } @@ -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; }