Unable to select file when using UIDocumentPickerViewController initForOpeningContentTypes

1.7k views Asked by At

I'm trying to use the iOS 14 initForOpeningContentTypes: rather than the deprecated initWithDocumentTypes:inMode: and I'm unable to get access to files with the extension p8 (they are greyed out).

I'm trying the following code:

NSArray<UTType*> * contentTypes = @[[UTType typeWithFilenameExtension: @"p8"
                                                     conformingToType: UTTypeData]];
UIDocumentPickerViewController *documentPicker = nil;
documentPicker = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes: contentTypes];

The picker launches, but the file "myfile.p8" is greyed out and unselectable. What am I doing wrong here?

1

There are 1 answers

0
Justin Garcia On

Once I added the following to my application’s Info.plist I was able to select the file:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeIdentifier</key>
        <string>com.my-company.my-identifier</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>My Description</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>p8</string>
            </array>
        </dict>
    </dict>
</array>

Apparently it tells the system about the type. See this answer for info about UTExportedTypeDeclarations.