我在Swift中遇到了可达性类的问题,我正在使用以下代码来使其工作,但似乎有些错误......
import Foundation
class NetworkConnect {
static let sharedInstance = NetworkConnect()
private init() {
}
func connected() -> Bool {
var reachability : Reachability = Reachability.reachabilityForInternetConnection()
var networkStatus : NetworkStatus = reachability.currentReachabilityStatus
if networkStatus.value == NotReachable.value {
return false
} else {
return true
}
}
}
我收到此错误:
'Reachability.NetworkStatus' is not convertible to 'NetworkStatus'
我该如何解决?
答案 0 :(得分:0)
就我个人而言,我建议您使用tonymillion
替代Reachability
课程,可在此处找到:
https://github.com/tonymillion/Reachability
然后您可以在一行中确定连接:
let connected: Bool = Reachability.reachabilityForInternetConnection().isReachable()
如果您之前从未尝试过,我还建议您通过CocoaPods
进行安装。原因是谷歌将通过CocoaPods分发他们未来的所有iOS SDK,所以你现在可能已经开始使用它了:)