Hey everyone,
I'm encountering a strange issue with URLSession in my Swift app. I've implemented the URLSessionDelegate, specifically urlSession(_:dataTask:didReceive:) and urlSession(_:task:didCompleteWithError:), but they don't seem to be getting called at all when I start a data task.
Here's a simplified version of how I'm setting up the session and task:
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
let dataTask = session.dataTask(with: url) { data, response, error in
// This completion handler is called, but delegate methods are not.
if let error = error {
print("Completion handler error: \(error)")
} else if let data = data {
print("Completion handler received data.")
}
}
dataTask.resume()
I'm using a background session, but I've tried default and ephemeral configurations as well. I've checked that self is correctly set as the delegate. What am I missing?