iosios-app-extensionfileprovider-extension

How to display download progress with FileProviderExtension on iOS


I've got an App that implements all the bells and whistles of the FileProviderExtension. Now the question arises what is required to display download/upload progress in the Files app?

Out there is a single previously asked question with a rather vague answer which didn't yield any results.

This is the rough code of the startProvidingItem(at url: URL ...) function:

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()
    }
}

Where the DownloadDelegate calls the completionHandler either with an error or nil on success. This all works but even though the downloadTask has been registered with the FileProviderManager no progress is shown.

It starts showing the indeterminate spinner and Waiting to Download below the file. The download task definitely sends progress events (confirmed with the urlSession(..., totalBytesWritten: ...) method in DownloadDelegate) but the FileProvider seemingly ignores them.


TL;DR: What is required to make download progress work in a FileExtension?


Solution

  • I have implemented and it's working fine. (See https://forums.developer.apple.com/thread/91280#292614)