在UIDocumentPickerViewController中显示自定义UTI的图标 [英] Show Icons for Custom UTIs in UIDocumentPickerViewController

查看:243
本文介绍了在UIDocumentPickerViewController中显示自定义UTI的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的iOS应用程序会导出UTI. Info.plist的相关部分如下所示:

The iOS app I'm working on exports a UTI. The relevant parts of the Info.plist look like this:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.xml</string>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>GPX Document</string>
        <key>UTTypeIdentifier</key>
        <string>de.company.app.gpx</string>
        <key>UTTypeSize320IconFile</key>
        <string>Doc320.png</string>
        <key>UTTypeSize64IconFile</key>
        <string>Doc64.png</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>gpx</string>
            </array>
        </dict>
    </dict>
</array>

我希望该应用通过在...中打开"对话框来处理GPX文件,因此同一PLIST中也有一个文档类型定义(引用了UTI):

I want the app to handle GPX files via "Open in..." dialogues, so there's also a document type definition (which references the UTI) in the same PLIST:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Icon29.png</string>
            <string>Icon58.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>de.company.app.gpx</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>de.company.app.gpx</string>
        </array>
    </dict>
</array>

在Safari中打开GPX文件时,它将在视网膜设备上显示我在CFBundleTypeIconFiles下指定的图标,即Icon58.png.该应用程序还允许通过iOS 8中引入的UIDocumentPickerViewController类进行导入,而UTI定义可以很好地过滤iCloud Drive中的相关文件,但它不会显示我指定的任何图稿:

When opening GPX files in Safari, it displays the icon I specified under CFBundleTypeIconFiles, i.e., Icon58.png on a retina device. The app also allows imports via the UIDocumentPickerViewController class introduced in iOS 8, and while the UTI definition works fine for filtering relevant files in iCloud Drive, it does not show any of my specified artwork:

我确保所有引用的图像文件(Icon29.pngIcon58.pngDoc64.pngDoc320.png)确实位于应用程序捆绑包的根目录中.名称中的数字表示其高度(以像素为单位). Doc...文件为正方形,其他两个文件为

I have ensured all the referenced image files (Icon29.png, Icon58.png, Doc64.png, Doc320.png) are indeed in the app bundle's root directory. The numbers in their names indicate their height in pixels. The Doc... files are squares, the other two follow this specification (iPhone only).

我基本上有两个问题:

1)如何使UIDocumentPickerViewController为我们的UTI显示自定义图标?

1) How do I make the UIDocumentPickerViewController display custom icons for our UTIs?

2)是否还有其他使用UTTypeSize64IconFileUTTypeSize320IconFile的用例?

2) Are there any other use cases where UTTypeSize64IconFile and UTTypeSize320IconFile are used?

推荐答案

不幸的是,答案是除非您的应用程序可以控制如何将这些文件写入磁盘,否则无法完成此操作.在这种情况下,您可以子类化UIDocument并写出缩略图. 此处是由Apple工程师发布的原始答案,并发布在Apple开发者论坛(登录)上.必需的).它包括一个代码示例,以说明其完成方式.

Unfortunately, the answer is that it cannot be done unless your app has control over how these files are written to disk. In that case, you can subclass UIDocument and write out thumbnails. Here is the original answer posted by an Apple engineer, posted on the Apple developer forums (login required). It includes a code sample to illustrate how it's done.

我还没有找到问题第二部分的答案.

I haven't found an answer to the second part of my question yet.

这篇关于在UIDocumentPickerViewController中显示自定义UTI的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆