【问题标题】:Associating my app's custom file in iOS在 iOS 中关联我的应用的自定义文件
【发布时间】:2012-02-24 16:40:30
【问题描述】:

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

How do I associate file types with an iPhone application?

文件名为 XXX.checklist

但它没有关联。我相信我的问题在于 public.mime-type 键,因为我不知道我应该放什么。以下是相关的 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>

【问题讨论】:

  • 我已经实现了上述解决方案。但我可以在共享菜单上看到我的应用程序。你能给我确切的答案吗

标签: ios file registration


【解决方案1】:

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

然后您应该简单地使用 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.datapublic.content 相同),因此当您使用此 UTI 时,附件的默认操作是在您的应用程序中打开它。

现在重点...您的CFBundleDocumentTypes 有一个额外的&lt;array&gt; 级别:

<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 部分已经可以了。

【讨论】:

  • 该文件只是一个文本 XML 文件。我放了 public.data,因为那是我看到的一个教程中的内容
  • 编辑了我上面的代码,以反映我从你的回答中学到的东西。不过还是不行
  • 哇,好收获。是的,现在可以了,谢谢。也感谢您的解释,因为我实际上了解我现在在做什么。我确实注意到电子邮件应用程序中的图标没有显示,它只是一个空白方块。我认为除了我上面所做的之外,定义文档图标没有什么特别之处?
  • 不客气,很高兴我能帮上忙。至于图标,你的定义没问题,图标可能会出现第二次左右。它也是第一次在我的应用程序中丢失。或者尝试更改邮件中的文件夹并返回带有附件的邮件,这也可能会有所帮助。
  • 您是否需要CFBundleDocumentTypesUTExportedTypeDeclarations 键才能通过自定义文件扩展名的文件启动应用程序?
猜你喜欢
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
相关资源
最近更新 更多