代码:
import Foundationimport SystemConfigurationpublic 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) { SCNetworkReachabilityCreateWithAddress(nil,UnsafePointer(import SystemConfigurationpublic 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) { SCNetworkReachabilityCreateWithAddress(nil,UnsafePointer()) } 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) }})) } 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) ? true : false}}
与代码错误:
如果它不可读,错误1说:
‘Int’ is not convertible to ‘SCNetworkReachabilityFlags’
错误2& 3:
Xcode 7.0 总结Could not find an overload for ‘init’ that accepts the supplIEd arguments
以上是内存溢出为你收集整理的检查互联网连接在Swift 2(iOS 9)全部内容,希望文章能够帮你解决检查互联网连接在Swift 2(iOS 9)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)