【问题标题】:Alamofire Time Out Not WorkingAlamofire 超时不工作
【发布时间】:2015-10-28 11:25:39
【问题描述】:

我在 swift 2.0 中使用 Alamofire 来执行发布请求。一切正常,但现在我必须为请求设置一个超时间隔,这就是我所做的:

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


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

现在 response.result.isSuccess 总是假的,不管我放了多少秒(1 到 1000)。这是为什么?请注意,调用不会等待 1000 秒然后得到此响应。

【问题讨论】:

    标签: swift2 alamofire


    【解决方案1】:

    对于任何有问题的人,这对我有用。

    设置一个全局变量

        var alamofireManager : Alamofire.Manager?
    

    然后

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-03
      • 2017-02-18
      • 2015-09-14
      • 2016-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      相关资源
      最近更新 更多