iOS custom UTI in UIDocumentPickerViewController initWithDocumentTypes
Asked Answered
S

2

2

I am trying to open .obj files from iCloud drive in my app throw UIDocumentPickerViewController. I could't find standart UTi for .obj files. So, using this https://developer.apple.com/library/content/qa/qa1587/_index.html I try to add support of this file-extension for my app.

there is info.plist sections :

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>arrow1</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>OBJ model</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.giena.Interface.obj</string>
        </array>
    </dict>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>OBJ model</string>
        <key>UTTypeIdentifier</key>
        <string>com.giena.Interface.obj</string>
        <key>UTTypeSize320IconFile</key>
        <string>arrow1</string>
        <key>UTTypeSize64IconFile</key>
        <string>arrow1</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>obj</string>
            </array>
        </dict>
    </dict>
</array>

and there is UIDocumentPickerViewController call:

 UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"]     inMode:UIDocumentPickerModeOpen];
    documentPicker.delegate = self;
    documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:documentPicker animated:YES completion:nil];

When i am running app, i see popup view for file choosing, but .obj files is grey and not-selectable. What am i doing wrong?

Setiform answered 26/6, 2017 at 18:40 Comment(2)
It looks like a bug... Today I try to do this actions with virtual file-extensions .tst and .xxxx and its work fine. But with .obj extension I have a problem.Setiform
you are trying to select .obj file but you mentioned "public.text" in document type. if you solved this then can you tell me what it would be exact for custom extension.Giselle
L
0

You should use your custom UTI in the list of document types:

UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];
Looming answered 2/1, 2018 at 14:8 Comment(0)
C
0

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>OBJ model</string>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>obj</string>
                </array>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>Obj file</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.giena.Interface.document.obj</string>
        </array>
    </dict>
</array>

and

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>OBJ model</string>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeIdentifier</key>
        <string>com.giena.Interface.document.obj</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>obj</string>
            </array>
        </dict>
    </dict>
    <dict/>
</array>

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

let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.giena.Interface.document.obj"], in: .import)

It should work

Caird answered 23/9, 2019 at 23:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.