How to set a different expiration timeout for each NSURLRequest

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

The only way I found is to create a new NSURLSession with another NSURLSessionConfiguration and modify timeoutIntervalForResource. Same thing with frameworks like Alamofire.

+4
source share
2 answers

You absolutely can do it. You can set the value directly to NSMutableURLRequest, which can be transferred to 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

timeoutIntervalForResource . - NSURLRequest timeoutIntervalForRequest NSURLSessionConfiguration. .

+5

, -

[[[NSURLSession sharedSession] configuration] setTimeoutForResource:30];

setTimeForResource .

-1

Source: https://habr.com/ru/post/1611932/


All Articles