我有一个只选择图像的UIDocumentPickerViewController。这在iOS 13中很好:
let supportedTypes: [String] = ["public.image"]
let documentPickerViewController = UIDocumentPickerViewController(documentTypes: supportedTypes, in: .import)我正试图在iOS 14中实现同样的目标。
然而,init(documentTypes:in:)在iOS 14.0中被否决。
所以我假设我必须使用这个初始化器来代替:init(forOpeningContentTypes:asCopy:)
forOpeningContentTypes参数需要一个UTType数组。
我不知道如何使用/导入它。
是不是像[UTType.Image]?
let supportedTypes: [UTType] = [UTType.Image]
self.viewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)这甚至不会编译,因为Cannot find type 'UTType' in scope。
我也尝试过import MobileCoreServices,甚至import CoreServices,但这并没有帮助。
文档对于新的文档选择器初始化程序指向这个UTTypeReference --所以我尝试使用它,但是也找不到它。
我怎么能拥有一个只在UIDocumentPickerViewController 14中选择图像的iOS呢?
更新
这是可行的(谢谢@Warren):
import UniformTypeIdentifiers
let supportedTypes: [UTType] = [UTType.image]
let pickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)发布于 2020-06-30 15:35:07
将import UniformTypeIdentifiers添加到您的快速文件中,以访问UTType
有关更多用法,请参见文献资料。
而WWDC2020视频“在SwiftUI中构建基于文档的应用程序”则是一个实用的演示。
https://stackoverflow.com/questions/62653008
复制相似问题