I'm trying to implement a Mutual TLS session on my app. I have already implemented a class that extends from URLSessionDelegate, URLSessionDataDelegate
I already have my _ session: URLSession, didReceive challenge: URLAuthenticationChallenge
implementation that "works" sometimes, and I say sometimes because is not always being called as it should.
This is my code where I use the dataTask
var urlRequest: URLRequest = setRequestHeaders(with: URLRequest(url: url))
urlRequest.method = .get
let sessionDelegate = MTLSURLSessionDelegate()
sessionDelegate.completionHandler = { [weak self] response in
// Here I handle my data after
// didReceive response: URLResponse
// didCompleteWithError error and didReceive data
}
let session = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: OperationQueue.main) // I have tried with a nil queue
let dataTask = session.dataTask(with: urlRequest)
dataTask.resume()
Like I said, this code is already working but sometimes I can see that the delegate is executing all its data delegate methods without calling _ session: URLSession, didReceive challenge: URLAuthenticationChallenge
first
Am I missing something here?