Alamofire 初探

2019-08-16  本文已影响0人  zhongxiaoyue

简介

Alamofire是一个用Swift编写的HTTP网络库。
大部分iOS开发的同学对于AFNetworking这个框架应该是非常熟悉的.很多App 都使用这个框架来进行网络访问.而Alamofire就是由AFNetworking的开发团队编写的Swift版网络框架.并且是基于AppleNSURLSession封装的,它在Apple的基础网络架构上提供了更加优雅的接口来简化繁重而常用的网络请求任务.

NSURLSession

在学习Alamofire之前,我们先来看一下Apple的请求网络的基本格式.

let configuration = URLSessionConfiguration.background(withIdentifier: self.createID())

let session = URLSession.init(configuration: configuration, delegate: self, delegateQueue: OperationQueue.main)

session.downloadTask(with: url).resume()

URL Loading System

iOS的网络开发(URL Loading System)的类层次如下:


Alamofire

基本用法

Alamofire.request(urlStr, method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).response { (response) in
    
    print("接收到了响应\(response)")
}
上一篇 下一篇

猜你喜欢

热点阅读