You need to use the NSMetadataQuery
approach.
When using iOS on iCloud, documents don't download automatically-- they only download when you ask for them. Using NSFileManager
as you suggest would only tell you if the file existed on the local device. But, the file might exist up in the cloud, not downloaded locally yet. If you use NSMetadataQuery
you can find out if the document exists anywhere, even if it's in the cloud and not actually downloaded yet. You can find out about the document if it was created on a different device. This also covers the case where the user deletes and reinstalls the app, but doesn't delete cloud data-- you find out if it exists even though it's not downloaded.
Since you're using UIManagedDocument
you shouldn't need to make a specific download call-- it will handle that for you when you open it.