2016-09-21 51 views

回答

1

由于在此link也是这个one答案,我的项目是运行完美,我的问题就解决了。

通过这样做:var reachability: Reachability!我可以检查网络可达性,而无需使用任何主机进行检查。

1
let reachability = Reachability(hostname: "http://whatYouWantToCheck.com") 

或尝试荚更新从GitHub

例如

let reachability = Reachability()! 

reachability.whenReachable = { reachability in 
    // this is called on a background thread, but UI updates must 
    // be on the main thread, like this: 
    dispatch_async(dispatch_get_main_queue()) { 
     if reachability.isReachableViaWiFi() { 
      print("Reachable via WiFi") 
     } else { 
      print("Reachable via Cellular") 
     } 
    } 
} 
+0

感谢您的回答,但对网络(通常)或特定链接进行的可达性测试?旧版本中的 –

+0

。你必须使用这个func reachabilityForInternetConnection(),但在新的你可以使用Reachability()尝试和更新你的库它可能不是最新的 –

+0

我更新了它,但我有同样的问题。你能给我一个正确的例子,从我能检查网络是否可用(不使用主机名)? –

相关问题