简体   繁体   English

获取iCloud Drive的内容

[英]Get the content of iCloud Drive

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. 在我的viewDidLoad中,我需要验证保存到iCloud Drive的文件是否仍然可用并且尚未删除。 As I have read, I can not use standard FileManager calls: 如我所读,我不能使用标准FileManager调用:

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. 我确实使用了NSMetadataQuery,但是我想知道是否有一种简便的方法可以在通知生效之前查询应用程序的UbiquitousDocument的内容。

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. 另外,我正在使用ios11工具在不同用户之间共享文件,并且再次需要能够验证当我的应用程序出现在前台时那些文件是否仍然可用。 Using the NSMetadataQuery and searching in NSMetadataQueryUbiquitousDocumentsScope the shared documents are not displayed. 使用NSMetadataQuery并在NSMetadataQueryUbiquitousDocumentsScope中搜索时,不会显示共享文档。
Any suggestions 有什么建议么
Best 最好
Reza 雷扎

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. 这将检查公共文档目录下的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM