【问题标题】:Selecting folders with UIDocumentBrowserViewController使用 UIDocumentBrowserViewController 选择文件夹
【发布时间】:2020-01-31 06:39:48
【问题描述】:

我正在开发一个新应用程序,我希望用户能够从 iCloud 或外部驱动器中选择一个文件夹。如何允许他们使用 UIDocumentBrowserViewController 选择文件夹?

我尝试将 allowedContentTypes 设置为文件夹的 UTI 'public.directory',但文档浏览器不允许选择文件夹。

UIDocumentBrowserViewController(forOpeningFilesWithContentTypes: ["public.directory"])

【问题讨论】:

    标签: ios swift uikit uidocumentbrowserviewcontroller


    【解决方案1】:

    这是适用于 iOS 13 的 official Apple solution

    let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open)
    documentPicker.delegate = self
    documentPicker.directoryURL = startingDirectory
    present(documentPicker, animated: true)
    

    常量kUTTypeFolder 来自import CoreServices

    【讨论】:

      猜你喜欢
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 2013-09-21
      • 2017-09-22
      • 2011-11-11
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多