How to expose and retrieve files in iCloud Drive on iOS8 provided by OS X application

2.7k Views Asked by At

I can store files into iCloud Drive programmatically from an OS X app (10.10) and from an iOS app (8.4) using a common ubiquity identifier (ex: iCloud.com.mycompany.CommonFiles), with the same Apple ID.

In the OS X application, I can identify or retrieve all the files in iCloud Drive, regardless of where they originated (locally or remotely), using that "common" ubiquity ID and NSFileManager contentsOfDirectoryAtURL: etc.

In iOS 8 however, although the iOS app seems to put files in the right place in iCloud Drive (such that they're visible in an OS X Finder, and retrievable in OS X), it can ONLY identify and retrieve files that it generated - files in iCloud Drive created on any other device are invisible to the iOS app.

What do I have to do in an iOS app to see and use (programmatically, not via the UIDocumentPicker) ALL the ubiquitous contents of the Documents directory that originated under the same common ubiquity identifier?

(This used to work in the old "Documents and Data" - pre iCloud Drive - technique where the "common" ubiquity identifier was prefixed with our company team ID - now replaced with "iCloud". Once users opted-in to iCloud Drive, however, that approach to common file sharing between apps on OS X and iOS was lost.)

1

There are 1 best solutions below

0
On

You should only enumerate the files in your app's iCloud Drive folder using NSMetadataQuery. Files in that directory will only show up after you have specifically asked to download them, and in order to ask for that, you need to know that they exist in the cloud (which you can only find out with NSMetaDataQuery).

See e.g. https://www.raywenderlich.com/12816/icloud-and-uidocument-beyond-the-basics-part-3 and for details https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/QueryingMetadata.html.