0

What’s the most convenient method to check whether a document is in iCloud or not?

Initially I was going to remove the last path component and compare the item url with the container url (assuming it’s non-nil) but realised that it doesn’t take into account possible subdirectories (e.g folders) if I choose to implement them later on.

Thanks

Adam Carter
  • 4,741
  • 5
  • 42
  • 103

1 Answers1

0

Use an NSMetadataQuery to search for your documents, then when the query returns the array of NSMetadataItems it has found, examine the item's you're interested in using something like:

BOOL isDownloaded = [[item valueForAttribute:NSMetadataUbiquitousItemDownloadingStatusKey] isEqualToString:NSMetadataUbiquitousItemDownloadingStatusCurrent];
BOOL isUploaded = [[item valueForAttribute:NSMetadataUbiquitousItemIsUploadedKey] boolValue];

If an item is both downloaded and uploaded then it is both in iCloud and exists locally on your device.

Rob Glassey
  • 2,237
  • 20
  • 21