ios - 在 iOS 中关联我的应用程序的自定义文件

标签 ios file registration

我正在尝试关联我的应用程序创建的自定义文件(它是 XML),以便用户可以通过电子邮件相互发送文件。我在这里遵循了优秀的教程:

How do I associate file types with an iPhone application?

文件名为XXX.checklist

但这不是联想。我相信我的问题出在 public.mime 类型的 key 上,因为我不知道我应该放在那里的是什么。下面是相关的 info-plist 条目

<key>CFBundleDocumentTypes</key>
<array>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>docIcon64.png</string>
                <string>docIcon320.png</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>My App Checklist</string>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>LSHandlerRank</key>
            <string>Owner</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.mycompany.appid.checklist</string>
            </array>
        </dict>
    </array>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.content</string>/// i tried public.text but it allowed the file to be opened by the devices default text viewer which I would not like. 
        </array>
        <key>UTTypeDescription</key>
        <string>My App Checklist</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.appid.checklist</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key> // fixed this key
            <string>checklist</string>
            <key>public.mime-type</key>
            <string>text/xml</string> /// changed to this, still doest work though
        </dict>
    </dict>
</array>

最佳答案

如果您的 UTI 声明为 public.data我假设您的 list 文件是自定义二进制数据。

然后你应该简单地使用 application/octet-stream作为 mime 类型。

更新: 明白了,你的问题比任何人想象的都要简单。对于初学者还有一件事 - public.data对于它的所有后代(包括 public.xml )都是可以的,因此对于 XML 文件,您可以设置以下任何一项:

  • public.item
  • public.data
  • public.content
  • public.text
  • public.xml

用于打开您的文件类型的应用程序列表是基于系统中可以处理给定 UTI 和您的 UTI 的已知应用程序构建的。由于默认文本编辑器打开 public.textpublic.xml这将是您的文件类型的默认操作(您的应用程序将显示在通过长按邮件附件调用的列表中)。

(显然)没有处理 public.data 的应用程序(与 public.content 相同),因此当您使用此 UTI 时,附件的默认操作是在您的应用中打开它。

现在进入正题……你的 CFBundleDocumentTypes多了一个<array>级别:

<key>CFBundleDocumentTypes</key>
<array>
    <array>     <!-- remove this line -->
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>docIcon64.png</string>
                <string>docIcon320.png</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>My App Checklist</string>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>LSHandlerRank</key>
            <string>Owner</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.mycompany.appid.checklist</string>
            </array>
        </dict>
    </array>     <!-- and this line -->
</array>

而且它会起作用。 UTExportedTypeDeclarations部分已经很好了。

关于ios - 在 iOS 中关联我的应用程序的自定义文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9434574/

相关文章:

iis-7 - 在注册时创建子域

ios - 像这张图片一样在 iOS 中导航

ios - 按主键排序的 Realm 结果数组并未实际排序

ios - Swift - 自定义 Segue 错误( 'view' 的使用不明确)

c - 获取文件大小而不读取文件

c - C中的可变大小数组。可以吗?

java - LibGDX JSON 对象保存/序列化

com - 从 Powerbuilder 应用程序调用 .Net COM 程序集(无需注册)

Javascript HTML 注册

ios - Xcode 编译错误