Swift 3.0迁移后的Alamofire错误:“在调用中额外的参数”(请求方法)

我目前正在更新我的代码库Swift 3.0,我正在使用Alamofire。
因此,我不得不将Alamofire更新到4.0(Alamofire git repo)。
我有一个请求的方法来从服务器获取数据,并在迁移之前,它的工作奇妙。
在使用Xcode的迁移工具之后,我结束了这个错误: "Extra argument in Call"
我不太确定为什么这种方法不再有效。
任何帮助将是美好的!

 class func makeRequest( _ method: RequestMethod, authorization: String?, uri: String, params: JSONDictionary?, retry: Bool = true, completionHandler: @escaping RequestCompletionBlock) { let requestURL = baseURL + uri let authHeader: Dictionary<String, String>? = authorization != nil ? ["Authorization" : authorization!] : nil //requestURL is highlighted, says "Extra argument in call" sharedAlamofireManager.request(Method(rawValue: method.rawValue)!, requestURL, parameters: params, encoding: .JSON, headers: authHeader).responseJSON { response in } } 

Alamofire4.0迁移指南

编辑:JSONDictionary:

 typealias JSONDictionary = Dictionary<String, Any> 

sharedAlamoFireManager也是一个SessionManager

每个AlamoFire文档The RequestAdapter protocol is a completely new feature in Alamofire 4. It allows each Request made on a SessionManager to be inspected and adapted before being created. One very specific way to use an adapter is to append an Authorization header to requests behind a certain type of authentication. The RequestAdapter protocol is a completely new feature in Alamofire 4. It allows each Request made on a SessionManager to be inspected and adapted before being created. One very specific way to use an adapter is to append an Authorization header to requests behind a certain type of authentication.

头不再是请求方法的参数,而是在请求适配器内部设置。

首先,我必须创buildAccessTokenAdapter类:

 class AccessTokenAdapter: RequestAdapter { private let accessToken: String init(accessToken: String) { self.accessToken = accessToken } func adapt(_ urlRequest: URLRequest) throws -> URLRequest { var urlRequest = urlRequest if urlRequest.urlString.hasPrefix(RequestManager.returnBaseURL()) { urlRequest.setValue("Bearer " + accessToken, forHTTPHeaderField: "Authorization") } return urlRequest } } 

然后我需要更新我的方法:

 class func makeRequest( _ method: RequestMethod, authorization: String?, uri: String, params: JSONDictionary?, retry: Bool = true, completionHandler: @escaping RequestCompletionBlock) { let requestURL = baseURL + uri var accessToken: String? if let authorization = authorization { accessToken = authorization }else{ accessToken = self.token()! } sharedAlamofireManager.adapter = AccessTokenAdapter(accessToken: accessToken!) sharedAlamofireManager.request(requestURL, method: .get, parameters: params, encoding: JSONEncoding.default) .responseJSON { response in } }