Do URLSessionDataDelegate and URLSessionDownloadDelegate work on Linux?

How can I see the download progress on Linux?

I tried URLSessionDataDelegate and URLSessionDownloadDelegate, both don't work.

public class SimpleJsonNetworkFetching:  NSObject & JsonNetworkFetching {//NSObject & JsonNetworkFetching  {
    public required convenience init(urlConfig: URLSessionConfiguration) {
        self.init()
        self.session = URLSession(configuration: urlConfig, delegate: self, delegateQueue: nil)
    }
}

extension SimpleJsonNetworkFetching: URLSessionDataDelegate, URLSessionDownloadDelegate {
    public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
        print("urlSession downloadTask")
    }

    public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
        print("urlSession didReceive")
    }

    public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
        print("urlSession adding")
    }

    public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
        print("urlSession error")
    }
}

none of the delegating methods are kicked in.

I haven't used Swift on Linux but your code only initialises the session. No tasks are being created and fired.

i did run it should be kicked in. I just didn't post here.

var request = URLRequest(url: url, cachePolicy: defaultURLRequestCachePolicy, timeoutInterval: defaultURLRequestTimeoutInterval)
request.httpMethod = "GET"
let task = session?.dataTask(with: request)

You forgot to resume() the task:

task.resume()

you are right. i totally forgot......

Terms of Service

Privacy Policy

Cookie Policy