问题
I have implemented 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.**
}
}
}
I am not able to get any UI handler in download delegates to update the progress and update the cell download button after successful download.
回答1:
To support progress display on download/upload progress, you need to do:
- Use NSURLSessionTask to download/upload files
- Use NSURLSession with backgroundSession ([NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:])
- Use [NSFileProviderManager registerURLSessionTask:forItemWithIdentifier:completionHandler:] to build task-identifier mapping.
Then the File Provider extension will show the progress on UI.
来源:https://stackoverflow.com/questions/48906577/nsfileproviderextension-extension-show-download-progress