我正在尝试关联我的应用程序创建的自定义文件(它是XML),以便用户可以通过电子邮件相互发送文件。我在这里遵循了优秀的教程:
How do I associate file types with an iPhone application?
该文件名为XXX.checklist
但这并不是联想。我认为我的问题出在put .mime类型的密钥上,因为我不知道我应该在那里放什么。下面是相关的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>发布于 2012-02-28 07:16:09
如果您的UTI声明为public.data,我假设您的检查表文件是一个自定义的二进制数据。
然后,您应该简单地使用application/octet-stream作为mime类型。
更新:明白了,你的问题比任何人想象的都要微不足道。对于初学者来说还有一件事- public.data对于它的所有后代(包括public.xml)都是可以的,所以对于XML文件,你可以设置其中的任何一项:
public.itempublic.datapublic.contentpublic.textpublic.xml提供用于打开您的文件类型的应用程序列表是基于系统中的已知应用程序构建的,这些应用程序可以处理给定的UTI加上您的应用程序。由于默认文本编辑器会打开public.text和public.xml,因此它将是您的文件类型的默认操作(您的应用程序将显示在长按邮件附件所调用的列表中)。
(显然)没有应用程序可以处理public.data (public.content也是如此),所以当您使用此工具时,附件的默认操作将是在您的应用程序中打开它。
现在直截了当地说。您的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部分已经很好了。
https://stackoverflow.com/questions/9434574
复制相似问题