From ef756b0065c16c0b193f163ee23eaaf507aab92c Mon Sep 17 00:00:00 2001 From: Christian Noon Date: Sat, 19 Mar 2016 11:33:06 -0700 Subject: [PATCH] Switched reachability over to using IPv4 for iOS 8.x and OSX 10.9.x. --- Source/NetworkReachabilityManager.swift | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/NetworkReachabilityManager.swift b/Source/NetworkReachabilityManager.swift index 63f97b6e4..fed66a225 100644 --- a/Source/NetworkReachabilityManager.swift +++ b/Source/NetworkReachabilityManager.swift @@ -114,20 +114,32 @@ public class NetworkReachabilityManager { } /** - Creates a `NetworkReachabilityManager` instance with the default socket address (`sockaddr_in6`). + Creates a `NetworkReachabilityManager` instance with the default socket IPv4 or IPv6 address. - returns: The new `NetworkReachabilityManager` instance. */ public convenience init?() { - var address = sockaddr_in6() - address.sin6_len = UInt8(sizeofValue(address)) - address.sin6_family = sa_family_t(AF_INET6) - - guard let reachability = withUnsafePointer(&address, { - SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) - }) else { return nil } - - self.init(reachability: reachability) + if #available(iOS 9.0, OSX 10.10, *) { + var address = sockaddr_in6() + address.sin6_len = UInt8(sizeofValue(address)) + address.sin6_family = sa_family_t(AF_INET6) + + guard let reachability = withUnsafePointer(&address, { + SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) + }) else { return nil } + + self.init(reachability: reachability) + } else { + var address = sockaddr_in() + address.sin_len = UInt8(sizeofValue(address)) + address.sin_family = sa_family_t(AF_INET) + + guard let reachability = withUnsafePointer(&address, { + SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) + }) else { return nil } + + self.init(reachability: reachability) + } } private init(reachability: SCNetworkReachability) {