首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIDocumentPickerViewController在iOS 14中的初始化

UIDocumentPickerViewController在iOS 14中的初始化
EN

Stack Overflow用户
提问于 2020-06-30 08:12:34
回答 1查看 10.5K关注 0票数 35

我有一个只选择图像的UIDocumentPickerViewController。这在iOS 13中很好:

代码语言:javascript
复制
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]

代码语言:javascript
复制
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):

代码语言:javascript
复制
import UniformTypeIdentifiers
let supportedTypes: [UTType] = [UTType.image]
let pickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-30 15:35:07

import UniformTypeIdentifiers添加到您的快速文件中,以访问UTType

有关更多用法,请参见文献资料

WWDC2020视频“在SwiftUI中构建基于文档的应用程序”则是一个实用的演示。

票数 48
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62653008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档