0

class Reachability check internet connection. This code

public class Reachability {
class func isConnectedToNetwork() -> Bool {
    var zeroAddress = sockaddr_in()
    zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
    zeroAddress.sin_family = sa_family_t(AF_INET)
    let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
        //SCNetworkReachabilityCreateWithName(nil, UnsafePointer($0))
        SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
    }

    var flags = SCNetworkReachabilityFlags.ConnectionAutomatic
    if !SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) {
        return false
    }
    let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
    let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
    return (isReachable && !needsConnection)
}
}

and test this

if Reachability.isConnectedToNetwork() == true {
   //code
}

how change this code class Reachability for support iPv6 ?

Alex
  • 1
  • 3
  • How exactly is it "not working"? What value do you get for the `flags`? – Martin R Dec 14 '16 at 07:50
  • sorry but I can not verify the connection through iPv6 I send an application to the apple and they returned with an error – Alex Dec 14 '16 at 08:25
  • So your app was *rejected?* Compare http://stackoverflow.com/questions/39631897/how-we-supourt-ipv6-for-reachability and http://stackoverflow.com/questions/39418928/ipv6-swift-reachability for very similar questions. – Martin R Dec 14 '16 at 08:32
  • According to https://github.com/ashleymills/Reachability.swift/issues/104, your code should work for IPv6. See https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/UnderstandingandPreparingfortheIPv6Transition/UnderstandingandPreparingfortheIPv6Transition.html#//apple_ref/doc/uid/TP40010220-CH213-SW16 for instructions how to test it in a IPv6 only environment. – Martin R Dec 14 '16 at 08:35
  • Yes, I found this statement, but I do not "Create NAT64 Network" checkbox so I replaced the code sockaddr_in -> sockaddr_in6 but it did not help – Alex Dec 14 '16 at 09:05
  • http://stackoverflow.com/a/40647059/1068283 – Michael Hampton Dec 14 '16 at 19:38
  • I check NAT64 network and my app not crashed. any ideas? – Alex Jan 26 '17 at 15:40

0 Answers0