我可以帮助找到我的SessionManager被解除分配的位置吗?接收Alamofire错误域= NSURLErrorDomain代码= -999“已取消”并且似乎无法绕过它或理解堆栈溢出中与此相同错误相关的许多其他重复问题?
THX
这是我的NetworkManager类NetworkManager.swift
class NetworkManager {
var defaultManager: Alamofire.SessionManager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"myserver.net": .pinCertificates(
certificates: ServerTrustPolicy.certificates(),
validateCertificateChain: false,
validateHost: false
),
]
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
return Alamofire.SessionManager(
configuration: configuration,
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
}()
}
我的ViewController.swift
func downloadspeakerData(completed: @escaping DownloadComplete) {
let headers: HTTPHeaders = [
"Accept": "application/json;odata=verbose",
"User-Agent": "iOS;iOS"
]
NetworkManager.init().defaultManager.request(qaSpeakerUrl, headers: headers).validate()
.responseJSON { response in
//print(Data.self)
print(response)
let result = response.result
//print(result)
if let dict = result.value as? Dictionary<String, AnyObject> {
if let list = dict["d"]?["results"] as? [Dictionary<String, AnyObject>] {
let titleDetails = list[0]["SpeakerName"] as? String
self._title = titleDetails
for obj in list {
let speaker = Speaker(speakerDict: obj)
self.speakers.append(speaker)
}
self.tableView.reloadData()
}
}
completed()
}
.authenticate(user: ("\(userfinal.0)"), password: ("\(userfinal.1)"))
}