fileImporter download progress from files in iCloud Drive

I'm using fileImporter for a Mac app. If I open a file from iCloud Drive that isn't already downloaded, I need to start the download before I can read the contents of the file. I found that I can download the file by using NSFileCoordinator or FileManager.default.startDownloadingUbiquitousItem.

These APIs will begin the download, but I have no updates on the progress or if the file has been downloaded. I've tried to use NSMetadataQuery with no luck.

Is there a way, either with fileImporter in SwiftUI or an AppKit API that I can receive updates for when a remote file has been downloaded, or do I need to prompt the users to download the file themselves before importing into my app?

It seems like you can read the download progress from the NSMetadataUbiquitousItemPercentDownloadedKey file metadata key.

You could probably initialize an NSMetadataItem using a URL object, then use the value(forAttribute:) function to fetch the download progress from 0.0 to 1.0.

fileImporter download progress from files in iCloud Drive
 
 
Q