Enumerating an iCloud Drive directory

241 Views Asked by At

I'd like to enumerate the files in a directory chosen by the user within a UIDocumentPickerViewController.

I get the directory URL returned from the document picker. I call startAccessingSecurityScopedResource I create an NSFileCoordinator instance and begin coordinated read of the directory. Inside my read handler I attempt to get the contents of the directory using FileManager.

I see that there are a bunch of blah.png.icloud files in the directory. This makes sense because I'm picking a directory within my iCloud drive.

What's the right way to enumerate the contents of this directory? I need to enumerate for two things: image meta data image data

Do I just need to trigger downloads of all the .icloud files to be able to read their image meta data?

I feel like NSMetaDataQuerys would be my best bet for this, but they don't seem to like using the URL provided to me by the document picker as the "query scope". (The queries begin, but never update or finish)

Anyone know of any good resources for this? I see a lot of stuff about reading the ubiquitous directories using NSMetaDataQueries, but not the directory locations chosen by a user via the document picker.

Bonus Question: Will I need to initiate full file downloads of the ".icloud" files in order to read their image meta data? (image width and height)

1

There are 1 best solutions below

1
On

I was able to get this to work using NSMetadataQuery.

let url = ... // URL retrieved using UIDocumentPickerViewController
let query = NSMetadataQuery()
query.searchScopes = [NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope, url]
query.predicate = NSPredicate(format: "%K like '*'", NSMetadataItemFSNameKey)