我如何检查Alamofire请求是否由于互联网连接失败而失败?我收到一个错误,但是我怎么知道它因此失败
Error Domain = NSURLErrorDomain代码= -1005“网络连接丢失。” UserInfo = {_ kCFStreamErrorCodeKey = -4,NSUnderlyingError = 0x6000007fe6a0 {Error Domain = kCFErrorDomainCFNetwork Code = -1005“(null)” UserInfo = {NSErrorPeerAddressKey = {length = 28,容量= 28,字节= 0x1c1e1f96000000000000000000000000 ... 0000000100000000},_kCFErrorCode -4,_kCFStreamErrorDomainKey = 4}},_ NSURLErrorFailingURLSessionTaskErrorKey = LocalUploadTask。<1>,_ NSURLErrorRelatedURLSessionTaskErrorKey =( “ LocalUploadTask。<1>” )
答案 0 :(得分:0)
您可以从失败案例中获取错误消息,
Alamofire.request("YourURL", method: .post, parameters: parameters)
.responseJSON { response in
if case .failure(let error) = response.result {
print(error.localizedDescription)//The network connection was lost.
} else if case .success = response.result {
print(response.result.value)
}
}