I've recently got an app rejected for not being compatible with IPv6. The app was causing a crash when the following code was called. I suspect the crash is because it makes use of SCNetworkReachabilityCreateWithAddress when Apple recommends to not use that anymore.
Could anyone give me a hand and help making this code below compatible with both IPv6 and IPv4?
Code
import Foundation
import SystemConfiguration
public class Reachability {
    class func isConnectedToNetwork() -> Bool {
        var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
        zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
        zeroAddress.sin_family = sa_family_t(AF_INET)
        let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
            SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)).takeRetainedValue()
        }
        var flags: SCNetworkReachabilityFlags = 0
        if SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) == 0 {
            return false
        }
        let isReachable = (flags & UInt32(kSCNetworkFlagsReachable)) != 0
        let needsConnection = (flags & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
        return isReachable && !needsConnection
    }
}
Code source:
Check for internet connection availability in Swift
Code call on view did load:
if Reachability.isConnectedToNetwork() == false
{
      // internet is down
      let error = NSError(domain: "", code: 3, userInfo: nil)           let alertView = createDefaultAlertError(error.code)
      let tryAgainAction = UIAlertAction(title: ClassGeneralMessages().userMessageTryAgain, style: UIAlertActionStyle.Default) { (UIAlertAction) in                
}
else
{
     // internet is ok
     // run more code here
}
 
     
     
     
     
     
    