Get the content of iCloud Drive

1.7k Views Asked by At

In my viewDidLoad, I need to verify if the files that I saved to the iCloud Drive are still available and have not been deleted. As I have read, I can not use standard FileManager calls:

FileManager.default.fileExists(atPath: filePath)

What would be the alternative. I do use NSMetadataQuery, but I wanted to know if there is an easy way to query the content of the App's UbiquitousDocument prior to the notifications kicking in.

Also, I am using the ios11 facility of sharing files between different users, and again I need to be able to verify if those files are still available when my App comes to the foreground. Using the NSMetadataQuery and searching in NSMetadataQueryUbiquitousDocumentsScope the shared documents are not displayed.
Any suggestions
Best
Reza

1

There are 1 best solutions below

2
On

Try this:

let DOCUMENTS_DIRECTORY = "Documents"
if let iCloudDocumentsURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)?.URLByAppendingPathComponent(DOCUMENTS_DIRECTORY)?.URLByAppendingPathComponent(fileName) {
    if let pathComponent = iCloudDocumentsURL.path {
        if (NSFileManager.defaultManager().fileExistsAtPath(pathComponent, isDirectory: nil)) {
        }
    }
}

This checks the file under the public Document directory.