【发布时间】:2020-02-11 07:54:09
【问题描述】:
在我们的项目中,我们使用网络管理器来处理所有使用 Alamofire 的请求和响应。在 alamofire 中,我们将默认的内部超时设置为 30。但是我们需要将某些请求的“timeoutIntervalForRequest”更改为 50,60 等。
private var manager : SessionManager?
func sessionManager() -> SessionManager {
if let manage = self.manager {
return manage
}
else {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
self.manager = SessionManager(configuration: configuration, delegate: CustomSessionDelegate())
return self.manager!
}
}
我已经添加了参数时间间隔并在其中设置了默认值。
func sessionManager(timeoutInterval:Double = 30) -> SessionManager {
//passed the param
configuration.timeoutIntervalForRequest = timeoutInterval
}
但是时间间隔值没有更新。我的问题是如何使用此函数为每个请求更新 SessionManager 的超时间隔。我们可以使用每个 API 的超时间隔来实现它,但我希望它高于通用功能。
【问题讨论】:
标签: ios swift networking alamofire