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?

Post not yet marked as solved Up vote post of Maximilian Down vote post of Maximilian
1.1k views

Replies

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.

  • Just to add on, I actually tried using NSMetadataQuery, and for some reason the ubiquitous item keys were all returning nil. Not too sure why it's happening, might have to talk to Apple Developer Technical Support for help.

Add a Comment