如何在iOS中注册一个自定义文件类型 [英] How do I register a custom filetype in iOS

查看:166
本文介绍了如何在iOS中注册一个自定义文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,我想让用户备份他们的文件(plist + m4a)。我压缩文件并将扩展名更改为自定义扩展名(专门针对我的应用程序,称为* .MyBackup)。然后,用户可以通过电子邮件或iTunes文件共享导出。



我已经阅读过有关CFBundleDocumentTypes但没有真正得到我对此的看法。 / p>

我目前停留的部分是如何将我的扩展名与我的应用关联。如果用户使用custom-zip文件发送自己的电子邮件,他应该可以使用我的应用程序打开它。



我该怎么做,什么是UTExportedTypeDeclarations?

解决方案

我希望如果我在我的项目info.plist的那部分转储没有太多的进一步的解释是没关系的。我认为这是非常不言自明的。

 < key> CFBundleDocumentTypes< / key> 
< array>
< dict>
< key> CFBundleTypeIconFiles< / key>
< array>
< string> Icon-iPad-doc320.png< / string>
< string> Icon-iPad-doc.png< / string>
< / array>
< key> CFBundleTypeName< / key>
< string> MyAppName File< / string>
< key> CFBundleTypeRole< / key>
< string> Viewer< / string>
< key> LSHandlerRank< / key>
< string>所有者< / string>
< key> LSItemContentTypes< / key>
< array>
<! - 我的应用程序支持带有自定义扩展名的文件(请参阅UTExportedTypeDeclarations) - >
< string> com.myurl.myapp.myextension< / string>
<! - 和csv文件。 - >
< string> public.comma-isolated-values-text< / string>
< / array>
< / dict>
< / array>



< key> UTExportedTypeDeclarations< / key>
< array>
< dict>
< key> UTTypeConformsTo< / key>
< array>
< string> public.data< / string>
< / array>
< key> UTTypeDescription< / key>
< string> MyAppName File< / string>
< key> UTTypeIdentifier< / key>
< string> com.myurl.myapp.myextension< / string>
< key> UTTypeTagSpecification< / key>
< dict>
< key> public.filename-extension< / key>
< string> myextension< / string>
< key> public.mime-type< / key>
< string> application / octet-stream< / string>
< / dict>
< / dict>
< / array>


I am currently creating a app in which i want to let the user backup their files (plist + m4a). I zip the files and change the extension to a custom one (specifically for my app, say "*.MyBackup"). The user can then either export via email or with iTunes file sharing.

I have already read about CFBundleDocumentTypes but didn't really get what I had to do with them.

The part where i am currently stuck at is how to associate my extension with my app. If the user sends himself an email with the "custom"-zip file he's supposed to be able to open it with my app.

How do I do this and what are "UTExportedTypeDeclarations"?

解决方案

I hope it's okay if I dump in that part of my projects info.plist without much further explanation. I think it's pretty much self-explanatory.

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Icon-iPad-doc320.png</string>
            <string>Icon-iPad-doc.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MyAppName File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <!-- my app supports files with my custom extension (see UTExportedTypeDeclarations) -->
            <string>com.myurl.myapp.myextension</string>
            <!-- and csv files. -->
            <string>public.comma-separated-values-text</string>
        </array>
    </dict>
</array>



<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>MyAppName File</string>
        <key>UTTypeIdentifier</key>
        <string>com.myurl.myapp.myextension</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>myextension</string>
            <key>public.mime-type</key>
            <string>application/octet-stream</string>
        </dict>
    </dict>
</array>

这篇关于如何在iOS中注册一个自定义文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆