Skip to content

Commit

Permalink
fix(iOS): Ensure IPv6 networks work correctly (#146 by @enahum)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum authored and matt-oakes committed Jul 19, 2019
1 parent d12eea8 commit f4e3378
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ios/RNCConnectionStateWatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "RNCConnectionStateWatcher.h"
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>

@interface RNCConnectionStateWatcher () <NSURLSessionDataDelegate>

Expand Down Expand Up @@ -56,7 +57,6 @@ static void RNCReachabilityCallback(__unused SCNetworkReachabilityRef target, SC
{
RNCConnectionStateWatcher *self = (__bridge id)info;
[self update:flags];

}

- (void)update:(SCNetworkReachabilityFlags)flags
Expand All @@ -71,7 +71,7 @@ - (void)setState:(RNCConnectionState *)state
{
if (![state isEqualToConnectionState:_state]) {
_state = state;

[self updateDelegate];
}
}
Expand All @@ -85,11 +85,22 @@ - (void)updateDelegate

- (SCNetworkReachabilityRef)createReachabilityRef
{
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "apple.com");
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;

SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *) &zeroAddress);
// Set the callback, setting our "self" as the info so we can get a reference in the callback
SCNetworkReachabilityContext context = { 0, ( __bridge void *)self, NULL, NULL, NULL };
SCNetworkReachabilitySetCallback(reachability, RNCReachabilityCallback, &context);
SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);

// Set the state the first time
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityGetFlags(reachability, &flags);
[self update:flags];

return reachability;
}

Expand Down

0 comments on commit f4e3378

Please sign in to comment.