我正在將我現有的Objective-C代碼(iOS)重寫爲Swift,現在我正面臨着與Apple的Reachability
類有關的一些問題,用於檢查網絡可用性......在我現有的代碼中,我使用以實現這一目標。在Swift中使用Apple的可達性類
var reachability: Reachability = Reachability.reachabilityForInternetConnection()
var internetStatus:NetworkStatus = reachability.currentReachabilityStatus()
if (internetStatus != NotReachable) {
//my web-dependent code
}
else {
//There-is-no-connection warning
}
而且我收到此錯誤:network status is not convertible to string
在這一行:
if (internetStatus != NotReachable)
是否有獲得網絡狀態的方法或類?
我需要這三個條件:
NotReachable: Obviously, there’s no Internet connection
ReachableViaWiFi: Wi-Fi connection
ReachableViaWWAN: 3G or 4G connection
這可能是有用的...... https://github.com/ashleymills/Reachability.swift – 2014-12-02 11:43:30
我增加了一個更完整的答案在這裏,我想:HTTP:/ /stackoverflow.com/a/29787876/210456 – Dragouf 2015-04-22 04:46:52
http://github.com/ashleymills/Reachability.swift現在有CocoaPod支持 – 2015-05-02 22:24:30