我在代码中使用了RetryPolicy
:
open class ConnectionLostRetryPolicy: RetryPolicy {
public init(retryLimit: UInt = RetryPolicy.defaultRetryLimit,
exponentialBackoffBase: UInt = RetryPolicy.defaultExponentialBackoffBase,
exponentialBackoffScale: Double = RetryPolicy.defaultExponentialBackoffScale,
retryableHTTPMethods: Set<HTTPMethod> = RetryPolicy.defaultRetryableHTTPMethods) {
super.init(retryLimit: retryLimit,
exponentialBackoffBase: exponentialBackoffBase,
exponentialBackoffScale: exponentialBackoffScale,
retryableHTTPMethods: retryableHTTPMethods,
retryableHTTPStatusCodes: [],
retryableURLErrorCodes: [.networkConnectionLost])
}
public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) {
print("TEST")
}
}
和我想适应每个请求来改变超时时间。但是adapt
函数没有被调用。我该怎么办?
我是这样用的:
let alamofire = AlamofireSession.shared
alamofire.session = Session(interceptor: ConnectionLostRetryPolicy())
这看起来像是Alamofire的某种包装,因为AlamofireSession
不是Alamofire提供的东西。一个AlamofireSession
有一个底层的.session
,即URLSession
。我建议你看看你正在使用的包装。