Reputation: 2992
I am currently trying to decrease the default values for timeoutIntervalForRequest
and timeoutIntervalForResource
of NSURLSessionConfiguration
for every Alamofire remote calls in my iOS app since I don't want it to wait 60 seconds and 7 days respectively.
This is my code:
Alamofire.Manager.sharedInstance.session.configuration.timeoutIntervalForRequest = 30
Alamofire.Manager.sharedInstance.session.configuration.timeoutIntervalForResource = 30
let parameters = [
"foo": [1,2,3],
"bar": [
"baz": "qux"
]
]
Alamofire.Manager.sharedInstance.request(.POST, "someURL", parameters: parameters, encoding: .JSON) {
(response) in
print(response.timeline)
}
This is my log:
Timeline: { "Latency": 60.977 secs, "Request Duration": 60.977 secs, "Serialization Duration": 0.000 secs, "Total Duration": 60.977 secs }
As you can see the Request Duration
value is over 30 seconds.
Does this depends on the fact that I use Alamofire.Manager.sharedInstance.request
instead of Alamofire.request
?
Upvotes: 0
Views: 1589
Reputation: 2992
I have opened an issue on the official Alamofire GitHub page and this was their opinion about that:
Changing the values of the configuration in a session that's already active has no effect. According to Apple's documentation on
NSURLSession
:Changing mutable values within the configuration object has no effect on the current session, but you can create a new session with the modified configuration object.
I suggest you create your manager instance and customize its configuration, as per our documentation.
Upvotes: 0
Reputation: 1521
I'm pretty sure it's because you can't change the configuration of the default Manager (or at least I don't think you can, might be a bug).
Try to instance a new one and add a customized NSURLSessionConfiguration.
ex:
var manager:Alamofire.Manager?
func initManager(timeoutInterval:Double) {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForRequest = timeoutInterval
configuration.timeoutIntervalForResource = timeoutInterval
manager = Alamofire.Manager(configuration: configuration)
}
// then use manager!.request to do your request
Upvotes: 1