现在的位置: 首页 > 综合 > 正文

注册你app所支持的文件类型以及Document interaction案例

2013年09月06日 ⁄ 综合 ⁄ 共 1606字 ⁄ 字号 评论关闭

概要点:

1. 你要注册(向ios/mac系统)申明app能够打开某种类型的文档,这样其他app才可能通过DIC(document interaction interface)把文件转给你app来打开

2. 注册就要在plist里声明: document types(我猜的),然后打开文本模式一看,果然对应了CFBundleDocumentTypes



<key>CFBundleDocumentTypes</key>

<array>

<dict>

<key>CFBundleTypeName</key>文档类型名称

<string>pdf</string>

<key>LSHandlerRank</key> //是拥有此类型文档,还是仅用于打开

<string>Default</string>

</dict>

</array>

一般而言一个文档类型和一个文件类型对应,当然也可以是多个文件类型例如。doc/。docx是word文档在两个不同版本下的文件后缀。这样你可以把这两个文件类型组合在一个文档类型中

A uniform type identifier (UTI) is a string that identifies a class of entities with a type.
UTIs are typically used to identify the format for files or in-memory data types and to identify the hierarchical layout of directories, volumes or packages

这里有个基本的对照表,文件后缀和UTI的串

https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

更多的对应可以参考:

 Apple's Uniform
Type Identifiers Overview

<key>LSItemContentTypes</key>
        <array>
            <string>com.sunsetlakesoftware.molecules.pdb</string> //app id+.pdb
            <string>org.gnu.gnu-zip-archive</string>
        </array>

这里我们使用了一个系统定义的。org。gnu。。。。另外一个是程序定义的UTI,程序定义的UTI需要导出,系统其他程序才能知道//

3. 需要为自定义的UtI在plist中申明:

<key>UTExportedTypeDeclarations</key>
<array>
   
<dict>
       
<key>UTTypeConformsTo</key>
       
<array>
           
<string>public.plain-text</string>
           
<string>public.text</string>
       
</array>
       
<key>UTTypeDescription</key>
       
<string>Molecules Structure File</string>
       
<key>UTTypeIdentifier</key>
       
<string>com.sunsetlakesoftware.molecules.pdb</string> // 自定义的type identifier
       
<key>UTTypeTagSpecification</key>
       
<dict>
           
<key>public.filename-extension</key> //关键点
           
<string>pdb</string>
           
<key>public

抱歉!评论已关闭.