liucaideNotes / LCD_Reachability

Swift - 网络连接类型判断
0 stars 1 forks source link

希望作者能升级到Swift4.0 #1

Open chengkaizone opened 6 years ago

chengkaizone commented 6 years ago

代码非常整洁干净,我尝试升级到Swift4.0, 但是指针那一块不太好处理,希望作者能处理下,非常感谢您对开源的贡献 谢谢!

chengkaizone commented 6 years ago

public class func reachabilityForInternetConnection() -> Reachability? {

    var zeroAddress = sockaddr_in()
    zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
    zeroAddress.sin_family = sa_family_t(AF_INET)

    let ref = withUnsafePointer(to: &zeroAddress) { ptr in
        SCNetworkReachabilityCreateWithAddress(nil, ptr.withMemoryRebound(to: UnsafePointer<sockaddr>.self, capacity: 1){ return $0.pointee })
    }

    return Reachability(reachabilityRef: ref)
}

具体这个方法是改动后的代码,可能有错误,会闪退