【问题标题】:Changing timeout time in Alamofire在 Alamofire 中更改超时时间
【发布时间】:2015-11-29 16:13:16
【问题描述】:

如何更改超时间隔时间以在 Alamofire 中获得长时间运行的 API 响应。

我尝试过以下代码:

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForRequest = 300.0 // seconds    
let alamofireManager = Alamofire.Manager(configuration: configuration)

alamofireManager.request(method, urlString, parameters: parameters)
        .authenticate(user: primaryUserName, password: primaryPassword)
        .validate(contentType: ["application/json"])
        .responseJSON {

            alamofireResponse in

            if alamofireResponse.response == nil {

               print("nil response")
            }
}

但它没有得到任何数据。响应为零。现在可以做什么?谢谢。

【问题讨论】:

  • 你能解决这个问题吗?

标签: swift alamofire


【解决方案1】:

您首先需要使用 3 秒超时创建自己的会话配置,然后创建自定义 Manager 实例。更多信息可以在README找到。

【讨论】:

  • 感谢您的回复。我在上面做的对吗?
  • 这个答案不正确 - 您已经在使用客户 SessionManager 并修改了超时值。
猜你喜欢
  • 2013-06-10
  • 2015-09-14
  • 2021-10-05
  • 2017-06-07
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
相关资源
最近更新 更多