Make sure the UI (managed) document is already in iCloud via URLForUbiquityContainerIdentifier + Path instead of NSMetadataQuery?

I have a fairly simple iOS app for iOS with 1 single database (like UIManagedDocument ) and thought about trying to add iCloud support .


I should of course check that an existing database already exists in the cloud * before creating a new UIManagedDocument on startup *, saving / opening, etc.

Since I already know the filename and that there is no document or document there at all, I really didn't get if I had to

  • run NSMetaDataQuery with the predicate for the exact file name and then get the file fileURL from the result (and upload it clearly?) and open it, if there is one, or

  • just use [[NSFileManager defaultManager] fileExistsAtPath:self.iCloudDBURL]

    with iCloudDBURL

    created from urlForUbiquityContainerIdentifier + add? Is this URL only local and does not automatically validate the "real" cloud?


I know that using UIManagedDocument might not be "correct" for such an application, but I thought it would be easier and I could try.

+3


source to share


1 answer


You need to take an approach NSMetadataQuery

.

With iOS, documents are not automatically downloaded to iCloud — they are only downloaded when requested. Usage NSFileManager

as you suggest will only tell you if the file exists on the local device. But the file can exist in the cloud and not be downloaded locally. If you use NSMetadataQuery

, you can find out if the document exists somewhere, even if it is in the cloud and hasn't been downloaded yet. You can find out about the document if it was created on another device. This also goes for the case where the user uninstalls and reinstalls the app but does not delete the cloud data - you will find if it exists even if it is not loaded.



Since you are using UIManagedDocument

, you will not need to make a specific download request - it will handle that for you when you open it.

+3


source







All Articles