Skip to content

Commit

Permalink
Switched reachability over to using IPv4 for iOS 8.x and OSX 10.9.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Mar 19, 2016
1 parent ca59c40 commit ef756b0
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Source/NetworkReachabilityManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ef756b0

Please sign in to comment.