0
votes

I have a basic iOS 8 app that lists the user's documents in the app's iCloud container and also in iCloud Drive.

My problem is that documents that are directly in iCloud Drive (Finder → Go → iCloud Drive) are not included as results of the metadata query. The query only returns results in the app's iCloud container's Documents folder.

I initialize the query like this:

self.query = [NSMetadataQuery new];
self.query.searchScopes = @[NSMetadataQueryUbiquitousDataScope,
   NSMetadataQueryUbiquitousDocumentsScope,
   NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope]; // iCloud Drive

The entitlements look like this:

<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
    <string>$(TeamIdentifierPrefix)com.my.app</string>
    <string>iCloud.com.my.app</string>
</array>

Even more strange: a few documents in iCloud Drive do show up sometimes, but if I move them out of iCloud Drive and back in, they do not show anymore.

2

2 Answers

2
votes

Figured it out. iCloud Drive documents are not in the app's container and therefore are not included in metadata query results, because the app has no access to external files.

Once a document was opened with a document picker, the app gets access to that document and it will from then on be part of metadata query results (until the user moves it out of iCloud Drive).

One more thing I observed: if the user moves the document out of iCloud Drive on a Mac, the metadata query will not receive an update on iOS. Trying to open the document on iOS simply results in an error (file not found).

0
votes

I also want to get the files and directories that directly in iCloud drive.I found an APP named "Document 5" has done this.This is my question:iCloud Drive list directories and files through NSMetadataQuery.