【问题标题】:Get the content of iCloud Drive获取 iCloud Drive 的内容
【发布时间】:2017-12-06 23:05:02
【问题描述】:

在我的 viewDidLoad 中,我需要验证我保存到 iCloud Drive 的文件是否仍然可用并且没有被删除。正如我所读到的,我不能使用标准的 FileManager 调用:

FileManager.default.fileExists(atPath: filePath)

还有什么选择。我确实使用 NSMetadataQuery,但我想知道是否有一种简单的方法可以在通知启动之前查询应用程序的 UbiquitousDocument 的内容。

另外,我正在使用 ios11 工具在不同用户之间共享文件,我需要再次验证当我的应用程序进入前台时这些文件是否仍然可用。使用 NSMetadataQuery 并在 NSMetadataQueryUbiquitousDocumentsScope 中搜索共享文档不会显示。
任何建议
最佳
雷扎

【问题讨论】:

  • 您知道您正在搜索的文件名吗?
  • 是的,知道文件路径,因此知道文件名
  • 太好了,一会儿再发布答案。让我知道是否有帮助

标签: swift ios11 icloud-drive


【解决方案1】:

试试这个:

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)) {
        }
    }
}

这会检查公共文档目录下的文件。

【讨论】:

  • 感谢您使用 Filemanager 调用来查询 iCloud 容器的内容
  • 是的,请在此处发布最终答案。
猜你喜欢
  • 2016-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 2019-12-17
  • 2015-12-02
  • 1970-01-01
  • 2020-12-06
相关资源
最近更新 更多