iOS自定义UTI/带有UIDocumentPickerViewController的文件类型

iOS自定义UTI/带有UIDocumentPickerViewController的文件类型,ios,uti,uidocumentpickerviewcontroller,Ios,Uti,Uidocumentpickerviewcontroller,我有一个自定义文件类型,我正试图允许我的应用程序从UIDocumentPickerViewController打开。然而,它不起作用。(类似的情况和问题似乎也有描述,但没有有效的解决方案。) 在我的Info.plist中,我有: <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key>

我有一个自定义文件类型,我正试图允许我的应用程序从UIDocumentPickerViewController打开。然而,它不起作用。(类似的情况和问题似乎也有描述,但没有有效的解决方案。)

在我的Info.plist中,我有:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>myext</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>document.icns</string>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>My document</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.app.document</string>
        </array>
        <key>NSPersistentStoreTypeKey</key>
        <string>Binary</string>
    </dict>
</array>
问题是,我的iCloud帐户中的“测试文件I.myext”显示如下:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeIconFiles</key>
                <array/>
                <key>CFBundleTypeName</key>
                <string>My Extension</string>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>myext</string>
                </array>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>myext file</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.app.document.myext</string>
        </array>
    </dict>
</array>
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document.myext"], in: .import)

i、 例如,一个灰显、不可选择、无法识别的文件


我希望我做了一些明显的错误,但我看不出来。

你必须这样写:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeIconFiles</key>
                <array/>
                <key>CFBundleTypeName</key>
                <string>My Extension</string>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>myext</string>
                </array>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>myext file</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.app.document.myext</string>
        </array>
    </dict>
</array>
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document.myext"], in: .import)

应该行得通

我也有同样的问题。我甚至在文件上看到我的应用图标,但我无法在文档浏览器中选择它。提供的答案可能是正确的,但可以从解释中获益。仅代码答案不被视为“好”答案。
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document.myext"], in: .import)