【问题标题】:NSFileProviderExtension extension show download ProgressNSFileProviderExtension 扩展显示下载进度
【发布时间】:2018-02-21 12:59:45
【问题描述】:

我已经实现了 FileProvider Extension。

class MyProviderExtension: NSFileProviderExtension {

    override func startProvidingItem(at url: URL, completionHandler: ((_ error: Error?) -> Void)?) {
            downloading file using URL and implemented download delegates

// Download Delegate
    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {

**// How can I upload the download progress here.**
}

   }
}

我无法在下载委托中获取任何 UI 处理程序来更新进度并在成功下载后更新单元格下载按钮。

【问题讨论】:

    标签: ios swift fileprovider-extension


    【解决方案1】:

    要支持下载/上传进度的进度显示,您需要做:

    1. 使用 NSURLSessionTask 下载/上传文件
    2. 使用 NSURLSession 和 backgroundSession ([NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:])
    3. 使用 [NSFileProviderManager registerURLSessionTask:forItemWithIdentifier:completionHandler:] 构建任务标识符映射。

    然后 File Provider 扩展将在 UI 上显示进度。

    【讨论】:

    • 如果我们需要执行多个 NSURLSessionTask 以完成下载,该怎么办?
    猜你喜欢
    • 2019-01-31
    • 2016-02-04
    • 2021-10-26
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多