Reputation: 12678
I am having trouble with a URLSession
that creates and resumes a URLSessionDataTask
in the sense that I expect subsequent calls to certain methods in the session's (and task`s) delegate but apparently no such calls occur.
How can I debug URLSession
in a situation like this? For instance, can I request log output from it e.g. to find out when it sends or receives HTTP traffic or when it attempts to call a method in the delegate but cannot find the relevant implementation (e.g. because the method signature in the implementation may be slightly off).
Upvotes: 0
Views: 1395
Reputation: 12678
Delegate methods are now (starting to be) called as expected. The solution consisted in copying method signatures from the very code base of URLSessionDataDelegate
and URLSessionTaskDelegate
(not their documentation) to ensure exact matches. Looking at device log output (lines with marked libsystem_network.dylib
and <Debug>
) was also helpful. The employed methods signatures are now as follows:
public func urlSession(_ session: URLSession,
task: URLSessionTask,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void) {
// ...
}
public func urlSession(_ session: URLSession,
dataTask: URLSessionDataTask,
didReceive data: Data) {
// ...
}
public func urlSession(_ session: URLSession,
task: URLSessionTask,
didCompleteWithError error: Error?) {
// ...
}
Upvotes: 1