首页 > 解决方案 > 如何在 iOS 文档选择器中选择 .pgw 文件?

问题描述

我正在开发一个需要从本地设备存储读取 .pgw 文件( https://en.wikipedia.org/wiki/World_file )的 iOS 应用程序。我的设备上有一个示例文件,我正试图从应用程序中打开它。当我打开文档选择器时,我可以看到该文件,但它是灰色的,我无法选择它。在该屏幕截图中,malaysia-google-earth.pgw 是我要打开的文件。

如果我将该文件的文件扩展名更改为 .txt,它不再灰显,我可以选择它。所以我知道这是文件扩展名的问题。

我尝试将 .pgw 添加到应用程序支持的文档类型列表中,但由于此扩展没有统一类型标识符,我不确定我是否正确添加它。我的 Info.plist 文件包含以下键:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>PNG World File</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.pgw</string>
        </array>
    </dict>
</array>

<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

<key>UIFileSharingEnabled</key>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>PNG World File</string>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeIdentifier</key>
        <string>public.pgw</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>pgw</string>
            </array>
        </dict>
    </dict>
</array>
<true/>

我使用的是 iOS 版本 13.6,这是一个使用 react-native-document-picker 的 React Native 应用程序。

标签: iosreact-nativereact-native-iosdocument

解决方案


推荐阅读