我正在尝试为Swift的Alamofire设置客户端每个请求的超时时间。首席架构师告诉我要在NSURLRequest上设置超时时间,但我完全不知道该如何实际操作。
有没有做过这个的人可以给个例子?谢谢!
我正在尝试为Swift的Alamofire设置客户端每个请求的超时时间。首席架构师告诉我要在NSURLRequest上设置超时时间,但我完全不知道该如何实际操作。
有没有做过这个的人可以给个例子?谢谢!
我认为这段代码可能可行。
var alamofireManager : Alamofire.Manager?
func some(){
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForResource = 2 // seconds
self.alamofireManager = Alamofire.Manager(configuration: configuration)
self.alamofireManager!.request(.GET, "http://example.com/")
.response { (request, response, data, error) in
}
}
这是如何使用URLRequest
设置每个请求超时时间的方法:
Alamofire.request(URLRequest(url: ..., cachePolicy: ..., timeoutInterval: 10))
.response(...)