仅在 iOS 13.3 上获取请求超时,但在 iOS 13.3 以下可以正常工作。
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x60000193b060
{Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102,
_kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <8F950888-C8E6-47B6-9FD8-78719B4FD231>.<8>,
_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <8F950888-C8E6-47B6-9FD8-78719B4FD231>.<8>"
),
NSLocalizedDescription=The request timed out.,
NSErrorFailingURLStringKey=https://api.url.com/oauth,
NSErrorFailingURLKey=https://api.url.com/oauth, _kCFStreamErrorDomainKey=4}
请帮助我。
代码片段是 -
func commonNetworkCallWithHeader(header :[String:String],url:String,method:HTTPMethod,parameters : [String:Any]?,completionHandler:@escaping (JSON?,String?)->Void) {
let configuration = URLSessionConfiguration.background(withIdentifier: "")
let manager = Alamofire.SessionManager(configuration: configuration)
manager.session.configuration.timeoutIntervalForRequest = 60
manager.startRequestsImmediately = true
manager.request(url, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
if(response.result.isSuccess){
if let data = response.result.value{
let json = JSON(data)
completionHandler(json,nil)
return
}
}
completionHandler(nil,response.result.error?.localizedDescription)
}
}