Alamofire正在API调用失败

时间:2018-03-13 06:52:16

标签: ios swift alamofire

在api调用中,每次都会进入成功块,但有时会有相同的请求返回失败块。一切都工作正常,但当我尝试多次请求时,它会进入失败状态。这是代码:

class func makeRequest(with url: String, method: HTTPMethod , success: @escaping ( response: Any) -> Void, failure: @escaping ( error: String) -> Void) {


    Alamofire.request(url, method: method,  encoding: JSONEncoding.default).responseJSON { (response) in
        switch (response.result) {
        case .success(let value):
            if let jsonData = try? JSONSerialization.data(withJSONObject: value, options: .prettyPrinted) {
                print("Response: \n",String(data: jsonData, encoding: String.Encoding.utf8) ?? "nil")
            }
            success(value)
        case .failure(let error):
            print(error.localizedDescription)
            failure("Failed")
        }
    }
}

错误说明:

2018-03-13 13:33:44.581060+0530 ***** TIC Read Status [17:0x6000001681c0]: 1:54
2018-03-13 13:33:44.584038+0530 ***** Task <E773098C-875E-49DF-B2EA-F14F8F35C217>.<9> HTTP load failed (error code: -1005 [4:-4])
2018-03-13 13:33:44.584421+0530****** Task <E773098C-875E-49DF-B2EA-F14F8F35C217>.<9> finished with error - code: -1005
Request failed with error: The network connection was lost.
The network connection was lost.

但没有连接问题。如果我按时间间隔一个接一个地发送请求,则执行成功块。只有在同一时间多次发送相同请求时才会出现问题。

0 个答案:

没有答案