Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alamofire ignores timeoutIntervalForRequest and timeoutIntervalForResource parameters #1332

Closed
giulio92 opened this issue Jul 5, 2016 · 3 comments
Assignees
Labels

Comments

@giulio92
Copy link
Contributor

giulio92 commented Jul 5, 2016

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": "qui"
    ]
]

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?

@jshier
Copy link
Contributor

jshier commented Jul 10, 2016

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.

@jshier jshier closed this as completed Jul 10, 2016
@giulio92
Copy link
Contributor Author

Hello @jshier, first of all thank you for your reply. I am sorry but I don't agree with that, because I have place the following code

Alamofire.Manager.sharedInstance.session.configuration.timeoutIntervalForRequest = 30 Alamofire.Manager.sharedInstance.session.configuration.timeoutIntervalForResource = 30

before performing a request, as you can see from my question aswell. Maybe I made the mistake not to explain it any further in the question post but I can confirm you 100% I did not had any other Alamofire request opened and that was also the first performed in the app. So: what session could be active in this situation?.

I have also tried to place the configuration code in the didFinishLaunchingWithOptions func but it didn't work.

@cnoon
Copy link
Member

cnoon commented Jul 14, 2016

@jshier is absolutely correct here @giulio92. Your code will not end up doing anything. Instead, you need to do what @jshier suggested and either create a custom Manager instance, or set the values on each NSURLRequest you make, but then you won't be able to use the top-level APIs.

Cheers. 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants