如何在iOS中注册自定义文件类型

JNK*_*JNK 15 email iphone import backup cfbundleidentifier

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

我已经阅读过关于CFBundleDocumentTypes的内容,但并没有真正了解我与它们有什么关系.

我目前所处的部分是如何将我的扩展程序与我的应用程序相关联.如果用户向自己发送了一封包含"自定义"-zip文件的电子邮件,他应该可以使用我的应用程序打开它.

我该怎么做以及什么是"UTExportedTypeDeclarations"?

Mat*_*uch 33

我希望如果我在没有进一步解释的情况下转储我的项目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>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>
Run Code Online (Sandbox Code Playgroud)

  • 我还提供了一些关于这些部分在我的答案中做了什么的更多解释:http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application/2781290 #2781290 (3认同)