Saturday, April 6, 2024
HomeiOS Developmentios - Technique inside `URLSessionDownloadDelegate` not getting referred to as

ios – Technique inside `URLSessionDownloadDelegate` not getting referred to as


Right here is the a part of half code. The extension on ViewController has two strategies. The primary one getting referred to as, however the second not getting referred to as as soon as startDownload() referred to as.

// Initialising URLSession
non-public var session: URLSession!
    
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    tremendous.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    let configuration = URLSessionConfiguration.default
    session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
}
@objc non-public func startDownload()  {
    guard let url = URL(string: "https://recordsdata.testfile.org/AUDIO/C/M4A/sample1.m4a") else {
        return
    }
    let downloadTask = session.downloadTask(with: URLRequest(url: url))
    downloadTask.resume()
}
extension ViewController: URLSessionDownloadDelegate {
    // This mehthod is getting referred to as
    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
        print("Completed Downloading")
    }
    
    // This technique will not be getting referred to as in any respect
    func urlSession(_ session: URLSession, process: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
        let fractionReceived = Float(totalBytesSent) / Float(totalBytesExpectedToSend)
        print(fractionReceived)
        progressView.progress = fractionReceived
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments