Bro*_*die 2 file registration ios
我正在尝试关联我的应用程序创建的自定义文件(它是XML),以便用户可以将文件通过电子邮件发送给对方.我在这里遵循了优秀的教程:
该文件名为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>
Run Code Online (Sandbox Code Playgroud)
如果您的UTI被声明为public.data我假设您的清单文件是自定义二进制数据.
然后你应该简单地使用application/octet-streammime类型.
更新:
知道了,你的问题比任何人都期望的更微不足道.对于初学者来说还有一件事 - public.data对于它的所有后代(包括public.xml)都是可以的,因此对于XML文件,您可以设置以下任何一个:
public.itempublic.datapublic.contentpublic.textpublic.xml提供打开文件类型的应用程序列表是基于系统中的已知应用程序构建的,可以处理给定的UTI以及您的UTI.由于默认文本编辑器打开public.text,public.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>
Run Code Online (Sandbox Code Playgroud)
它会起作用.这UTExportedTypeDeclarations部分已经很好了.