UIDocumentPickerViewController的documentTypes

最近在研究UIDocumentPickerViewController的使用,在他的初始化方法里就被卡住了,对其中documentTypes这个参数,系统注释里写的很少,网上找也废了很大的力气,这里总结一下。

先来看一下这个初始化方法:

1
2
// Initializes the picker instance for selecting a document in a remote location. The valid modes are Import and Open.
public init(documentTypes allowedUTIs: [String], in mode: UIDocumentPickerMode)

这个参数是要传入一个字符串数组,数组的内容是需要支持的文件类型。如果想深究这些字符串是如何定义,为什么这么定义,请移步这里,本篇文章只讲用什么。

先列几个常用的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
"com.microsoft.powerpoint.​ppt",
"com.microsoft.word.doc",
"com.microsoft.excel.xls",
"com.microsoft.powerpoint.​pptx",
"com.microsoft.word.docx",
"com.microsoft.excel.xlsx",
"public.avi",
"public.3gpp",
"public.mpeg-4",
"com.compuserve.gif",
"public.jpeg",
"public.png",
"public.plain-text",
"com.adobe.pdf"

大家看后缀名应该就能看懂。

至于完整版,大家可以看这里:
苹果官方文档

文章目录
|