gpt4 book ai didi

ios - Alamofire - 不接受 failureCallBack 中的错误

转载 作者:行者123 更新时间:2023-11-30 12:17:17 24 4
gpt4 key购买 nike

我们正在使用 Alamofire pod。现在我面临 NSError 的问题。

当我们编写 error: responseObj.result.error 时,Swift 3 不接受这一点。帮我解决这个问题。

检查我的代码:

static func getDataFromAPI(parameters : [String : AnyObject], successCallBack : @escaping APISuccessCallBack, failureCallBack : @escaping APIFailureCallBack) {

client.makePOSTRequest(service: Constants.API_BASE_URL, parameters: parameters) { (statusCode, response, error) -> () in

if statusCode == MobomoAPIClient.HTTPStatusCode.Success {
successCallBack(response)
}
else {
failureCallBack(client.responseErrorMessage(statusCode: statusCode, response: response, error: error!))
}
}
}

typealias APIClientResponseCallBack = (_ statusCode: Int?, _ response : AnyObject?, _ error : Error?) -> ()

func makePOSTRequest (service : String!, parameters : [String: AnyObject]? = nil, responseCallBack : APIClientResponseCallBack!) {
self.sendRequest(method: .post, service: service, parameters: parameters, responseCallBack: responseCallBack);
}

private func sendRequest (method: Alamofire.HTTPMethod, service : String!, parameters : [String: AnyObject]? = nil, responseCallBack : APIClientResponseCallBack!) {

var headers : [String : String] = [String : String]()
headers["Accept-Version"] = "1.0"
var urlString = self.urlStringWithService(service: service)
urlString = Constants.API_BASE_URL

self.alamoFireManager!.request(urlString, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.responseJSON { (responseObj) -> Void in
responseCallBack(statusCode: responseObj.response?.statusCode, response: responseObj.result.value as AnyObject, error: responseObj.result.error)
}
}

最佳答案

responseCallBack(responseObj.response?.statusCode, responseObj.result.value as AnyObject, responseObj.result.error)

这对我有用

关于ios - Alamofire - 不接受 failureCallBack 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45237698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com