Handle timeout with Alamofire

后端 未结 9 1654
暗喜
暗喜 2020-12-01 05:24

Is it possible to add timeout handler for Alamofire request?

In my project I use Alamofire this way:

init() {
    let configuration = NSURLSessionCon         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 05:59

    Swift 3.x

    Accepted answer didn't worked for me too.

    This work for me!

    let url = URL(string: "yourStringUrl")!
    var urlRequest = URLRequest(url: url)
    urlRequest.timeoutInterval = 5 // or what you want
    

    And after:

    Alamofire.request(urlRequest).response(completionHandler: { (response) in
        /// code here
    }
    

提交回复
热议问题