ios - 使用 UIDocumentBrowserViewController 选择文件夹
问题描述
我正在开发一个新应用程序,我希望用户能够从 iCloud 或外部驱动器中选择一个文件夹。如何允许他们使用 UIDocumentBrowserViewController 选择文件夹?
我尝试将 allowedContentTypes 设置为文件夹的 UTI,“public.directory”,但文档浏览器不允许选择文件夹。
UIDocumentBrowserViewController(forOpeningFilesWithContentTypes: ["public.directory"])
解决方案
这是适用于 iOS 13的官方 Apple 解决方案:
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open)
documentPicker.delegate = self
documentPicker.directoryURL = startingDirectory
present(documentPicker, animated: true)
常数kUTTypeFolder
来自import CoreServices
。
推荐阅读
- wix - 在 wix 安装程序中使用 cutomAction DriverPackageInstall 安装驱动程序
- java - 两个 Set 包含相同的元素,但它们不相等。为什么会有这样的结果?
- android - 如何像在 iOS 中为 iMessage 一样为 Android 创建贴纸包?
- vb.net - 类型“集合”未定义 vb BC30002
- java - 将具有动态确定类型参数的对象传递给 2 参数方法,其两个参数具有相同的类型参数
- c++ - 用于 where 子句的 Odbc 空值绑定
- c# - 无法在 LINQ to Entities 查询中构造实体或复杂类型 X
- linux - 两个 Linux 服务器之间的 PowerShell 远程执行
- javascript - AngularJS 参数“fn”不是函数,未定义
- javascript - Meteor 客户端无法访问已编译的生产文件