本文转载至 http://blog.csdn.net/zaitianaoxiang/article/details/6658492

File type handling is new with iPhone OS 3.2, and is different than the already-existing custom URL schemes. You can register your application to handle particular document types, and any application that uses a document controller can hand off processing of these documents to your own application.

文件类型处理是iphone os 3.2新增的,与已经存在的自定义URL方案是不同的。你能注册你的应用程序来处理特定的文件类型并且任何应用程序 使用文档控制器能手动处理这些文档在你的应用程序中。

For example, my application Molecules (for which the source code is available) handles the .pdb and .pdb.gz file types, if received via email or in another supported application.

例如,我的molecules应用程序能处理 以 pdb , pdb.gz为后缀的文件类型 ,如果收到通过电子邮件或其他支持的应用程序。

To register support, you will need to have something like the following in your Info.plist:

注册支持,你需要在info.plist文件中增加像下面一样的内容。

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Document-molecules-320.png</string>
            <string>Document-molecules-64.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MoleculesStructureFile</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.sunsetlakesoftware.molecules.pdb</string>
            <string>org.gnu.gnu-zip-archive</string>
        </array>
    </dict>
</array>

Two images are provided that will be used as icons for the supported types in Mail and other applications capable of showing documents. The LSItemContentTypes key lets you provide an array of Uniform Type Identifiers (UTIs) that your application can open. For a list of system-defined UTIs, see Apple's Uniform Type Identifiers Reference. Even more detail on UTIs can be found in Apple's Uniform Type Identifiers Overview. Those guides reside in the Mac developer center, because this capability has been ported across from the Mac.

两个图像将作为支持的邮件和其他应用程序能够显示文件类型的图标。LSItemContentTypes键可让您提供一个可以使您的应用程序打开的统一类型标识符(UTI)数组。对于一个系统定义的UTI的列表,请查看苹果的Uniform Type Identifiers Reference(统一类型标识符参考)。UTI更详细信息,可以在苹果公司的Uniform Type Identifiers Overview(统一类型标识符的概述)中找到。这些指南位于Mac开发中心,因为这种能力已经从Mac移植通过。

One of the UTIs used in the above example was system-defined, but the other was an application-specific UTI. The application-specific UTI will need to be exported so that other applications on the system can be made aware of it. To do this, you would add a section to your Info.plist like the following:

上面的例子中用到的UTI的一种是系统定义的,还有其他应用程序特定的UTI。应用程序特定的UTI 需要被导出,以使系统上的其他应用程序能知道它。要做到这一点,你需要像下面一样添加一部分内容到你的info.plist文件中。

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.plain-text</string>
            <string>public.text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>MoleculesStructureFile</string>
        <key>UTTypeIdentifier</key>
        <string>com.sunsetlakesoftware.molecules.pdb</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>pdb</string>
            <key>public.mime-type</key>
            <string>chemical/x-pdb</string>
        </dict>
    </dict>
</array>

This particular example exports the com.sunsetlakesoftware.molecules.pdb UTI with the .pdb file extension, corresponding to the MIME type chemical/x-pdb.

这个特殊的例子导出com.sunsetlakesoftware.molecules.pdb UTI (以.pdb为文件扩展名,对应的MIME类型为 chemical/x-pdb)

With this in place, your application will be able to handle documents attached to emails or from other applications on the system. In Mail, you can tap-and-hold to bring up a list of applications that can open a particular attachment.

在此,您的应用程序将能够处理连接到电子邮件或系统上其他应用程序的文件。在邮箱中,你可以轻按和按住去弹出一个可以打开一个特定附件的应用程序列表。

When the attachment is opened, your application will be started and you will need to handle the processing of this file in your -application:didFinishLaunchingWithOptions: application delegate method. It appears that files loaded in this manner from Mail are copied into your application's Documents directory under a subdirectory corresponding to what email box they arrived in. You can get the URL for this file within the application delegate method using code like the following:

打开附件时,您的应用程序将被启动,您将需要在您的应用程序中处理这个文件通过didFinishLaunchingWithOptions:应用程序委托方法。看来,通过这种从相应收到的电子邮件中的文件复制到应用程序的文件目录下的子目录中的加载方式,通过应用程序中的委托方法,类似于下面的代码的方法,您可以得到此文件:

NSURL*url=(NSURL*)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];

Note that this is the same approach we used for handling custom URL schemes. You can separate the file URLs from others by using code like the following:

请注意,这是我们处理自定义的URL计划使用相同的方法。通过使用类似于下面的代码,你可以区分其开其他的文件URL

if([url isFileURL])
{
    // Handle file being passed in
}
else
{
    // Handle custom URL scheme
}

UTI iPhone支持依文件后缀名打开应用的更多相关文章

  1. 如何让Composer的autoload支持自定义文件后缀名

    PHP的Composer工具规范了我们对系统各种资源库的加载格式,借助于PHP的自动加载机制,可以很大程度上简化在应用开发过程中的类库文件引用场景.但到目前为止,它有个不是问题的问题,就是文件后缀名只 ...

  2. java使用新的(nio)遍历文件(支持文件后缀名、文件名正则表达式匹配)

    import org.junit.Test; import java.io.IOException; import java.nio.file.Files; import java.nio.file. ...

  3. Linux下的文件及文件后缀名

    Linux下的文件及文件后缀名 2013-03-14 15:34 6969人阅读 评论(0) 收藏 举报 ++++++++++++++++++++++++++++++++++++++正文+++++++ ...

  4. 关于Windows下的文件后缀名问题

    一.背景说明 有很多的小伙伴对windows下的文件后缀名不能很好地理解作用和区别,更不用说高深的使用了,在这里给大家说一下这些文件后缀名到底有什么区别,有什么作用呢? 二.说明 简单的说来,wind ...

  5. -05 08:57 ARCGIS地统计学计算文件后缀名为.shp文件制作

    2011-07-05 08:57 ARCGIS地统计学计算文件后缀名为.shp文件制作 ARCAMP软件要进行地统计计算的文件后格式后缀名必须为.shp的文件,网上介绍的方法复杂难懂,那么制作.shp ...

  6. C#文件后缀名详解

    C#文件后缀名详解 .sln:解决方案文件,为解决方案资源管理器提供显示管理文件的图形接口所需的信息. .csproj:项目文件,创建应用程序所需的引用.数据连接.文件夹和文件的信息. .aspx:W ...

  7. return 通过文件后缀名得到的函数字符串

    <?php//图片处理工具类class Image{//属性private $thumb_width; //缩略图的宽private $thumb_height;//错误属性public $th ...

  8. 你误解了Windows的文件后缀名吗?

    一.背景说明 有很多的小伙伴对windows下的文件后缀名不能很好地理解作用和区别,更不用说高深的使用了,在这里给大家说一下这些文件后缀名到底有什么区别,有什么作用呢? 二.说明 简单的说来,wind ...

  9. Win10怎么批量修改文件后缀名?

    Win10怎么批量修改文件后缀名?一般我们都是右击重命名,但是,如果要改的文件很多的话,这样做事不行的,该怎么批量修改后缀名呢?下面我们一起来看看两种解决办法 通常我们修改文件后缀名都是右击>& ...

随机推荐

  1. TestNG+ReportNG+Maven优化测试报告

    转载:https://www.cnblogs.com/hardy-test/p/5354733.html 首先在eclipse里面创建一个maven项目,具体要配置maven环境,请自行百度搭配环境. ...

  2. 使用网桥模式(bridge networking mode)配置KVM-QUME虚拟机网络

    (1)linux要工作在网桥模式,所以必须安装两个RPM包.即:bridge-utils和tunctl.它们提供所需的brctl.tunctl命令行工具.能够使用yum在线安装: [root@serv ...

  3. javascript中按位操作的应用,如何快速取整 判断字符串是否是包含某字符串

    最近在看最基础的<javascript高级程序设计>看的灰常慢,看到按位运算这里,突然反思,这种鬼操作到底有什么实际的应用呢? 按位运算符有6个 & 按位与:a & b | ...

  4. 初识 Java

    1.Java中的数据类型 Java 语言是一种强类型语言.通俗点说就是,在 Java 中存储的数据都是有类型的,而且必须在编译时就确定其类型. Java 中有两类数据类型: 在 Java 的领域里,基 ...

  5. PgSql备份pg_dump与还原手记pg_restore(转)可以直接跳转至最后面的示例进行查看

    PgSql备份pg_dump与还原手记pg_restore(转) 可以直接跳转至最后面的示例进行查看 真没有想到,以前一直是PostgreSQL使用者,突然需要库移植又成了头一招了!原来它与mysql ...

  6. ActiveMQ简述

    概述 ActiveMQ是Apache所提供的一个开源的消息系统,全然採用Java来实现.因此.它能非常好地支持J2EE提出的JMS(Java Message Service,即Java消息服务)规范. ...

  7. jQuery select的操作实现代码

          //改变时的事件  $("#testSelect").change(function(){ //事件发生生 jQuery('option:selected', this ...

  8. SpringCloud系列十五:使用Hystrix实现容错

    1. 回顾 上文讲解了容错的重要性,以及容错需要实现的功能. 本文来讲解使用Hystrix实现容错. 2. Hystrix简介 Hystrix是Netflix开源的一个延迟和容错库,用于隔离访问远程系 ...

  9. Linux tomcat安装详解(未完)

    转: http://blog.csdn.net/lcyaiym/article/details/76696192

  10. VS项目名称修改

    阅读数:11141 VS中新建一个项目,如果开发工作都接近尾声,客户来要求更换项目的名称,差不多要变更整个解决方案中项目名称,引用等等,这个工作量还是很大的.上网搜索解决方法,还实验了专门的修改项目名 ...