简体   繁体   English

在 RetryPolice 中调整 Alamofire 请求

[英]Adapt Alamofire requests in RetryPolice

i used RetryPolicy in my code with this class:我在我的代码中使用了RetryPolicy和这个 class:

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")
    }
}

and i want to adapt per request to change timeout time.我想根据请求调整以更改超时时间。 but adapt func does not called.但不会调用adapt func。 what should i do?我应该怎么办?

i used it like this:我这样使用它:

let alamofire = AlamofireSession.shared
alamofire.session = Session(interceptor: ConnectionLostRetryPolicy())

This looks like some sort of wrapper for Alamofire, as AlamofireSession isn't something Alamofire provides.这看起来像是 Alamofire 的某种包装器,因为AlamofireSession不是 Alamofire 提供的东西。 An Alamofire Session has an underlying .session , which is the URLSession . Alamofire Session有一个底层.session ,即URLSession I suggest you look into whatever wrapper you're using.我建议您查看您正在使用的任何包装器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM