carlhung
(Carlhung)
1
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.
eimantas
(Eimantas)
2
I haven't used Swift on Linux but your code only initialises the session. No tasks are being created and fired.
carlhung
(Carlhung)
3
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)
eimantas
(Eimantas)
4
You forgot to resume() the task:
task.resume()
carlhung
(Carlhung)
5
you are right. i totally forgot......