nsurlconnection - 在 NSURLSession/NSURLConnection 上使用 Alamofire 进行网络有什么优势?

标签 nsurlconnection alamofire nsurlsession mobile-application

谁能帮助我理解这些问题:使用 Alamofire 优于 NSURLSession/NSURLConnection 有什么优势?

NSURLSession 和 NSURLConnection 有什么区别?

最佳答案

Alamofire 建立在 NSURLSession 之上,与 (POST/GET/PUT/etc) 进行 REST 交互的代码行数更少。它将为您提供“90%”的方法,但如果您需要进行 super 专业的网络调用,则需要使用 NSURLSession。

例如:获取 JSON 的简单 Alamofire 调用

Alamofire.request(.GET, "https://www.google.com/",encoding: .JSON).responseJSON {response in
        if(response.result.error == nil){
            print(response.data)
        }else{
            print("Network Error")
        }
}

NSURLConnection 现在已被弃用,而 NSURLSession 是新标准。
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html

关于nsurlconnection - 在 NSURLSession/NSURLConnection 上使用 Alamofire 进行网络有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470840/

相关文章:

ios - Swift 4 - 使用 PromiseKit 调用嵌套

swift - Alamofire 相当于 AFHTTPSessionManager

ios - 无法从 Alamofire 返回获取数据

ios - NSURLConnectionDownloadDelegate destinationURL

objective-c - 来自 HTTP 状态代码的 NSError

iphone - NSURLConnection 协议(protocol)在哪里?

swift - 无法将图像快速上传到服务器

ios - 一个 NSURLSession 中所有 NSURLSessionTasks 的平均进度

codeigniter - NSURLSession iOS CodeIgniter 不发送 POST

iphone - iOS 缓存策略