2

我有一个应用程序,它实现了 FileProviderExtension 的所有花里胡哨。现在问题出现了,在文件应用程序中显示下载/上传进度需要什么?

有一个先前提出的问题,答案相当模糊,没有产生任何结果。

这是startProvidingItem(at url: URL ...)函数的粗略代码:

let downloadDelegate = DownloadDelegate(completionHandler, targetLocation: url, fileManager: fileManager)
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: downloadDelegate, delegateQueue: nil)
let downloadTask = session.downloadTask(with: sftpURL)

NSFileProviderManager.default.register(downloadTask, forItemWithIdentifier: id) { error in
    if let error = error {
         print("Error registering progress task \(error)")
    } else {
         print("Registered progress task")
         downloadTask.resume()
    }
}

DownloadDelegate调用completionHandler错误或nil成功的地方。这一切都有效,但即使 downloadTask 已注册但FileProviderManager没有显示任何进度。

Waiting to Download它开始在文件下方显示不确定的微调器。下载任务肯定会发送进度事件(通过 中的urlSession(..., totalBytesWritten: ...)方法确认DownloadDelegate),但 FileProvider 似乎忽略了它们。


TL;DR:在 FileExtension 中使下载进度正常工作需要什么?

4

1 回答 1

0

我已经实施并且工作正常。(见https://forums.developer.apple.com/thread/91280#292614

  • URLSession 应该使用 .background 配置。
  • 配置应该有一个有效的 sharedContainerIdentifier。
  • 您的扩展的容器应用程序应该有权访问共享容器。

  • 扩展应该通过 documentSize 属性报告正确的文件大小。

于 2019-02-15T07:00:45.967 回答