Skip to content

Commit 3e45854

Browse files
Merge pull request #3 from alburdette619/bugfix/isconnected-crash
Seperated SCNetworkReachabilityRef instances
2 parents 3d1795f + 05eadcc commit 3e45854

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Libraries/Network/RCTNetInfo.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ - (void)startObserving
8282
_connectionType = RCTConnectionTypeUnknown;
8383
_effectiveConnectionType = RCTEffectiveConnectionTypeUnknown;
8484
_statusDeprecated = RCTReachabilityStateUnknown;
85-
[self setupReachability];
85+
_reachability = [self getReachabilityRef];
8686
}
8787

8888
- (void)stopObserving
@@ -94,12 +94,14 @@ - (void)stopObserving
9494
}
9595
}
9696

97-
- (void)setupReachability
97+
- (SCNetworkReachabilityRef)getReachabilityRef
9898
{
99-
_reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, _host.UTF8String ?: "apple.com");
99+
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, _host.UTF8String ?: "apple.com");
100100
SCNetworkReachabilityContext context = { 0, ( __bridge void *)self, NULL, NULL, NULL };
101-
SCNetworkReachabilitySetCallback(_reachability, RCTReachabilityCallback, &context);
102-
SCNetworkReachabilityScheduleWithRunLoop(_reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
101+
SCNetworkReachabilitySetCallback(reachability, RCTReachabilityCallback, &context);
102+
SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
103+
104+
return reachability;
103105
}
104106

105107
- (BOOL)setReachabilityStatus:(SCNetworkReachabilityFlags)flags
@@ -163,8 +165,8 @@ - (BOOL)setReachabilityStatus:(SCNetworkReachabilityFlags)flags
163165
RCT_EXPORT_METHOD(getCurrentConnectivity:(RCTPromiseResolveBlock)resolve
164166
reject:(__unused RCTPromiseRejectBlock)reject)
165167
{
166-
[self setupReachability];
167-
CFRelease(_reachability);
168+
SCNetworkReachabilityRef reachability = [self getReachabilityRef];
169+
CFRelease(reachability);
168170
resolve(@{@"connectionType": _connectionType ?: RCTConnectionTypeUnknown,
169171
@"effectiveConnectionType": _effectiveConnectionType ?: RCTEffectiveConnectionTypeUnknown,
170172
@"network_info": _statusDeprecated ?: RCTReachabilityStateUnknown});

0 commit comments

Comments
 (0)