您好,我正在我的应用程序中使用 swift2.2 开发一个应用程序,我想检查互联网连接,所以我遵循了一种方法 http://www.brianjcoleman.com/tutorial-check-for-internet-connection-in-swift/ .它现在运行良好我也想检查慢速互联网进程,因为当互联网非常慢时我的应用程序会导致崩溃。我不知道如何处理它我已经检查了很多堆栈流答案没有任何帮助可以有人帮助我处理这个过程....
最佳答案
如果你想在调用网络服务之前检查是否有互联网连接,你可以使用第三方库 Reachability 和
如果没有互联网,你可以做任何你想做的事,比如加载图标之类的
objective-c
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
if (internetStatus != NotReachable) {
//webservice implementation
}
else {
//no internet connection
}
swift
class func hasConnectivity() -> Bool {
let reachability: Reachability = Reachability.reachabilityForInternetConnection()
let networkStatus: Int = reachability.currentReachabilityStatus().rawValue
return networkStatus != 0
}
关于ios - 如何快速处理缓慢的互联网进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42784977/