为Alamofire全局设置超时间隔

时间:2017-10-23 15:48:58

标签: ios swift alamofire nsurlsession

我在整个项目中都使用了Alamofire:

Alamofire.request("http://my.api.com", method: .get, parameters: ["some": "thing"], encoding: URLEncoding.default, headers: myHeaders)

是否可以快速设置我上述所有请求的超时时间?我没有运气就尝试了以下内容

Alamofire.SessionManager.default.session.configuration.timeoutIntervalForRequest = 10
Alamofire.SessionManager.default.session.configuration.timeoutIntervalForResource = 10

1 个答案:

答案 0 :(得分:0)

    let configuration = URLSessionConfiguration.default
    configuration.timeoutIntervalForRequest = 10
    let manager = Alamofire.SessionManager(configuration: configuration)