由于IPV6网络中的应用程序崩溃,App Store拒绝了iOS Swift 3应用程序

时间:2017-07-17 05:25:25

标签: swift3 app-store ipv6 ios10.3.2

我的应用程序被App Store拒绝,因为它在IPV6网络中崩溃了。这件事发生在我身上。我已经更新了我的代码以支持IPV6网络,并且在该代码中成功移动了两个版本。

但现在他们又提出了同样的问题,他们说这个问题只发生在Wi-Fi网络上。这是我尝试过的代码:

internal class Reachability
    {
        class func isConnectedToNetwork() -> Bool
        {
            var zeroAddress = sockaddr_in6()
            zeroAddress.sin6_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
            zeroAddress.sin6_family = sa_family_t(AF_INET6)

            let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {
                $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in
                    SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "www.google.com")
                }
            }

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

2 个答案:

答案 0 :(得分:0)

你可以尝试一下吗,它可以为我工作3g,4g和wifi网络也很好用。旧的不支持移动网络中的连接。

class func isConnectedToNetwork() -> Bool
    {
        var zeroAddress = sockaddr_in()
          zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
       // zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
        zeroAddress.sin_family = sa_family_t(AF_INET)

        let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
            SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, UnsafePointer($0))
        }

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

答案 1 :(得分:0)

User