quasiceo / 待分类1 / UTI iPhone支持依文件后缀名打开应用

0 0

   

UTI iPhone支持依文件后缀名打开应用

2014-11-04  quasiceo

UTI iPhone支持依文件后缀名打开应用

(2012-05-07 13:41:08)
标签:

杂谈

分类: ios

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
}
分享:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。如发现有害或侵权内容,请点击这里 或 拨打24小时举报电话:4000070609 与我们联系。

    猜你喜欢

    0条评论

    发表

    请遵守用户 评论公约

    类似文章
    喜欢该文的人也喜欢 更多