小编ieg*_*j33的帖子

使用 SwiftUI 显示 SessionDownloadDelegate 的进度

我正在尝试使用 SwiftUI 组合一个杂志浏览应用程序,但在尝试创建下载进度指示器时遇到了障碍。我似乎无法找到一种方法来使ProgressBar我从urlSession(didWriteData)in进行更新URLSessionDownloadDelegate

我有一个DownloadManager作为环境对象传递给主视图的单曲,它处理所有杂志问题的下载。

class DownloadManager: NSObject, URLSessionDownloadDelegate, ObservableObject {

    var activeDownloads: [URL: Download] = [:]

    lazy var downloadSession: URLSession = {
        let config = URLSessionConfiguration.default
        return URLSession(configuration: config, delegate: self, delegateQueue: nil)
    }()

    /*downloading and saving the issues is handled here*/

    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
        guard
            let url = downloadTask.originalRequest?.url,
            let download = activeDownloads[url]
            else {
                return
        }
        //this is the …
Run Code Online (Sandbox Code Playgroud)

state download ios swift swiftui

4
推荐指数
1
解决办法
1005
查看次数

标签 统计

download ×1

ios ×1

state ×1

swift ×1

swiftui ×1