Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS custom UTI/filetype with UIDocumentPickerViewController

I've got a custom filetype that I'm trying to allow my app to open from a UIDocumentPickerViewController. It isn't, however, working. (A similar situation and problem seem to be described here, but there's no working solution.)

In my Info.plist I've got:

<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>

and:

<key>UTImportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array/>
        <key>UTTypeDescription</key>
        <string>My document</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.app.document</string>
        <key>UTTypeSize320IconFile</key>
        <string>document</string>
        <key>UTTypeSize64IconFile</key>
        <string>document</string>
        <key>public.filename-extension</key>
        <array>
            <string>myext</string>
            <string>MYEXT</string>
        </array>
    </dict>
</array>

and I'm instantiating things with:

let picker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document"],
                                            in: UIDocumentPickerMode.import)
picker.delegate = self
picker.modalPresentationStyle = UIModalPresentationStyle.fullScreen
self.present(picker, animated: true, completion: nil)

Problem is, "Test File I.myext" in my iCloud account comes out looking like this:

i.e., a grayed-out, non-selectable, unrecognized file.

I'm hoping I'm doing something obvious wrong, but I can't see it.

like image 910
KT_ Avatar asked Mar 20 '18 02:03

KT_


1 Answers

You have to put something like this:

<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>

and

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>My Extension File</string>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.app.document.myext</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>myext</string>
            </array>
        </dict>
    </dict>
    <dict/>
</array>

Also in your controller you have to put something like this:

let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.mycompany.app.document.myext"], in: .import)

It should work

like image 120
Jano Avatar answered Oct 26 '22 16:10

Jano