You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have set timeoutIntervalForRequest and timeoutIntervalForResource both for NSURLSessionConfiguration but service stop directly when I use below code.
func callService() {
// var alamoFireManager : Alamofire.Manager?
var alamoFireManager = Alamofire.Manager.sharedInstance
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForRequest = 10 // seconds
configuration.timeoutIntervalForResource = 10
alamoFireManager = Alamofire.Manager(configuration: configuration)
alamoFireManager.request(.GET, RequestCall.API_URL + request, parameters: parameters, encoding: .URL)
.responseJSON { response in
if let JSON = response.result.value {
print(JSON)
callback!((JSON as! NSDictionary))
}
}
}
Is any wrong with code? I want timeout when response not retrieve after 10 seconds.
The text was updated successfully, but these errors were encountered:
Dhvl-Golakiya
changed the title
Timeout is not working
Request timeout is not working
Jun 4, 2016
As soon as your code leaves callService(), there is no longer any reference to your alamoFireManager variable and it is deallocated, cancelling any pending requests you have. You're also redundantly setting alamoFireManager to the sharedInstance and then to a newly allocated instance later on.
What the documentation about custom Managers doesn't state is that you need to keep the manager around somehow. I like to use a static property in a struct:
Hi,
I have set
timeoutIntervalForRequest
andtimeoutIntervalForResource
both forNSURLSessionConfiguration
but service stop directly when I use below code.Is any wrong with code? I want timeout when response not retrieve after 10 seconds.
The text was updated successfully, but these errors were encountered: