Search code examples
swift2alamofire

Alamofire Time Out Not Working


i am using Alamofire in swift 2.0 to perform post requests. everything is working fine but now i have to set a time out interval on the request here is what i have done :

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
            configuration.timeoutIntervalForRequest = 300;
            let Manager = Alamofire.Manager(configuration: configuration)


            Manager.request(.POST, URL, parameters:param as? [String : AnyObject])......

now the response.result.isSuccess is always false no matter how many seconds i put (1 to 1000). why is that? and note that the call is not waiting for 1000 seconds and then getting this response.


Solution

  • for anyone having problem this worked for me.

    set a global variable

        var alamofireManager : Alamofire.Manager?
    

    then

     let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
                configuration.timeoutIntervalForResource = 1 // seconds for testing
    
                self.alamofireManager = Alamofire.Manager(configuration: configuration)
    
                 self.alamofireManager!.request(.POST, URL, parameters: param as? [String : AnyObject],  headers: headers)
    .responseString
                    { response in
    
                        print ("the response: \(response.description)") //will return a timeout error