如何应对swift中缓慢的互联网流程

时间:2017-03-14 11:39:07

标签: ios swift2 connectivity internet-connection

您正在我的应用程序中使用swift2.2开发应用程序我想检查互联网连接,所以我按照方法http://www.brianjcoleman.com/tutorial-check-for-internet-connection-in-swift/。它运行良好现在我也想检查缓慢的互联网进程,因为当互联网很慢我的应用程序导致崩溃。我不知道处理它我已经检查了许多堆栈流程答案没有任何帮助可以一些帮助我处理这个过程....

1 个答案:

答案 0 :(得分:1)

如果要在调用Web服务之前检查是否存在Internet连接,可以使用名为Reachability的第三方库和

如果没有互联网做你想要的任何东西,如加载图标或其他东西

目标C

Reachability *reachability = [Reachability reachabilityForInternetConnection];    
NetworkStatus internetStatus = [reachability currentReachabilityStatus];

if (internetStatus != NotReachable) {

//webservice implementation

}
else {

    //no internet connection
}

<强>夫特

class func hasConnectivity() -> Bool {
    let reachability: Reachability = Reachability.reachabilityForInternetConnection()
    let networkStatus: Int = reachability.currentReachabilityStatus().rawValue
    return networkStatus != 0
}