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?

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. Commented Jun 27, 2017 at 15:11
  • 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. Commented Oct 10, 2017 at 17:40

2 Answers 2

0

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

UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.