Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right Way for changing timeoutIntervalForRequest in Alamofire

I changed timeoutIntervalForRequest with

let manager = Alamofire.SessionManager.default
manager.session.configuration.timeoutIntervalForRequest = 3    
manager.request(url).response {}

but seems not worked, Any suggestion?

like image 856
d0ye Avatar asked Dec 23 '22 18:12

d0ye


1 Answers

This worked for me :)

let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = TimeInterval(7)
configuration.timeoutIntervalForResource = TimeInterval(7)
let session = URLSession(configuration: configuration)

let task = session.dataTask(with: url) {}

Changes to the configuration of an already initialized URLSession have no effect, per Apple's documentation. If you want a custom timeout, either set the value on your requests, or create a custom URLSession with a custom configuration, as outlined in document

like image 60
d0ye Avatar answered Feb 23 '23 00:02

d0ye