Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to select file when using UIDocumentPickerViewController initForOpeningContentTypes

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?

like image 269
Kyle Avatar asked Oct 15 '25 14:10

Kyle


1 Answers

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.

like image 86
Justin Garcia Avatar answered Oct 17 '25 20:10

Justin Garcia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!