Вот код из связанного ответа в Swift. НТН.
class RequestHelper: NSObject, URLSessionDelegate {
func makeRequest(request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) ->() ) {
let sessionConfiguration = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
let task = session.dataTask(with: request) { data, response, error in
completionHandler(data, response, error)
}
task.resume()
}
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition,
URLCredential?) -> () ) {
guard
challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
challenge.protectionSpace.host == "yourdomain.com",
let trust = challenge.protectionSpace.serverTrust
else {
return
}
let credential = URLCredential(trust: trust)
completionHandler(.useCredential, credential)
}
}