UIDocumentPickerViewController allows to select file declared in Info.plist document types even when restricting to folder UTI

My document-based UIKit app can open plain text files such as .txt files.

When tapping a particular button I want to be able to select a folder, but when using the code below, the document picker allows me to select folders as well as .txt files:

class DocumentViewController: UIDocumentViewController, UIDocumentPickerDelegate {

    override func viewDidAppear(_ animated: Bool) {
        let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
        documentPicker.delegate = self
        present(documentPicker, animated: true)
    }
    
}

If I remove the text file entry from the Info.plist's document types list, it works as expected. Is this a bug and if yes, is there a workaround?

	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeName</key>
			<string>Text</string>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>LSHandlerRank</key>
			<string>Default</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>public.text</string>
			</array>
		</dict>
	</array>

I created FB22254960.

Thank you for filing FB22254960 .

When your app declares support for public.text in CFBundleDocumentTypes, you're telling the system that your app can open text documents. The document picker respects your declaration and shows both the content types you explicitly request folder and the types your app supports.

Thanks for confirming. This is unexpected because from the documentation it sounds like only the provided UTIs are allowed by the document picker; there's no mention of the Info.plist types. Is there no way of allowing the user to select only the provided UTIs?

On macOS, regardless what document types the Info.plist contains, using the following code only allows to select folders:

let openPanel = NSOpenPanel()
openPanel.allowedContentTypes = [.folder]
openPanel.runModal()
UIDocumentPickerViewController allows to select file declared in Info.plist document types even when restricting to folder UTI
 
 
Q