Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set different expiration timeout for each NSURLRequest

Is it possible to set different expiration timeout for each request?

The only way I found was to create a new NSURLSession with a different NSURLSessionConfiguration and change the timeoutIntervalForResource. Same thing with frameworks like Alamofire.

like image 988
Luca Torella Avatar asked Sep 27 '22 11:09

Luca Torella


1 Answers

You absolutely can do this. You can set the value directly on an NSMutableURLRequest which can be passed into Alamofire.

let URL = NSURL(string: "https://httpbin.org/get")!
let mutableURLRequest = NSMutableURLRequest(URL: URL)
mutableURLRequest.timeoutInterval = 5.0

Alamofire.request(mutableURLRequest)
    .responseJSON { response in
        debugPrint(response)
    }

UPDATE

You cannot control the timeoutIntervalForResource per request. The timeout interval property on NSURLRequest is equivalent to timeoutIntervalForRequest on the NSURLSessionConfiguration. More details here.

like image 94
cnoon Avatar answered Oct 03 '22 12:10

cnoon