在我的 viewDidLoad 中,我需要验证我保存到 iCloud Drive 的文件是否仍然可用并且没有被删除。正如我所读,我不能使用标准的 FileManager 调用:
FileManager.default.fileExists(atPath: filePath)
还有什么选择。我确实使用 NSMetadataQuery,但我想知道是否有一种简单的方法可以在通知启动之前查询应用程序的 UbiquitousDocument 的内容。
此外,我正在使用 ios11 工具在不同用户之间共享文件,我再次需要能够验证当我的应用程序出现在前台时这些文件是否仍然可用。使用 NSMetadataQuery 并在 NSMetadataQueryUbiquitousDocumentsScope 中搜索共享文档不会显示。
任何建议
最好的
礼萨
最佳答案
试试这个:
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)) {
}
}
}
这会检查公共(public)文档目录下的文件。
关于swift - 获取 iCloud Drive 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47684984/