ios - 如何快速处理缓慢的互联网进程

标签 ios swift2 connectivity internet-connection

您好,我正在我的应用程序中使用 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/

相关文章:

iOS 本地化问题

swift - 如何首先显示另一个 View Controller (在 GameViewController.swift 之前)

Android:如何检查谷歌是否可用?

ios - 字符串比较失败

ios - iOS 和 tvOS 共享的 Cocoa Touch 框架

iphone - 如何在 iOS 中登录网站?

ios - Swift2.0 多点连接无法连接

swift - Swift 中重复的表格 View 单元格

azure - 无法使用 SQL 身份验证连接到 Azure SQL Server

安卓连接