gpt4 book ai didi

ios - 如何检查 Alamofire 因网络连接不良而失败?

转载 作者:行者123 更新时间:2023-11-29 05:46:30 35 4
gpt4 key购买 nike

如何检查我的 Alamofire 请求是否因互联网连接不良而失败?我收到错误,但我怎么知道它因此而失败

Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x6000007fe6a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey={length = 28, capacity = 28, bytes = 0x1c1e1f96000000000000000000000000 ... 0000000100000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalUploadTask .<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalUploadTask .<1>" )

最佳答案

您可以从失败案例中获取错误消息,如下所示

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)
}
}

关于ios - 如何检查 Alamofire 因网络连接不良而失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100991/

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