我想从某个 url 下载文件。我需要的是数据委托(给我下载数据的委托)。我实施了:
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
委托,但它没有被调用。
我的代码是:
func download(url: URL)
{
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig, delegate: self, delegateQueue: nil)
let task = session.downloadTask(with: url)
task.resume()
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
print("apending ")
self.dataaa.append(data)
}
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
print("here")
}
两个委托函数没有被调用!