转换为Alamofire 4打破了Alamofire.Request扩展

时间:2016-09-20 14:08:22

标签: alamofire swift3

我在Alamofire 3上有这个小扩展,它用于从默认响应中获取某些令牌和数据。

{
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'.",
    "details": [
      {
        "code": "CertificateImproperlyFormatted",
        "message": "The data retrieved from https://XXXX.vault.azure.net/secretsYYY/ZZZ is not deserializable into JSON."
      }
    ]
  }
}

现在在Alamofire 4和Swift 3中,返回响应{(req,res,data,error)in 中出现错误 错误是:

  

无法调用非函数类型'HTTPURLResponse'的值

我甚至试图这样做:

public extension Alamofire.Request {

    private func authorizationHandler(queue: dispatch_queue_t? = nil, completionHandler: (NSURLRequest, NSHTTPURLResponse?, NSData?, NSError?) -> Void) -> Self {
        return response { (req, res, data, error) in

            if let headers = res?.allHeaderFields {

                if let id = headers["x-uid"] as? String {
                    oHTTPEnvironment.x_uid = id
                }

                if let authToken = headers["x-access-token"] as? String {
                    oHTTPEnvironment.currentMutableToken = oHTTPEnvironment.nextMutableToken
                    oHTTPEnvironment.nextMutableToken = authToken
                }
            }

            dispatch_async(queue ?? dispatch_get_main_queue(), {
                completionHandler(req!, res, data, error)
            })
        }
    }
}

但它也会出现同样的错误。

0 个答案:

没有答案