I'm trying to open a picker with only certain file types allowed. I'm using this documentation to find the UTType I need: https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/system_declared_uniform_type_identifiers
But I can't find a UTType for .pages, .doc, .docx for example.
What should I do?
This is my code for the moment
func presentPickerDocument() {
//Create a picker specifying file type and mode
var supportedTypes: [UTType]
supportedTypes = [UTType.pdf, UTType.url]
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
present(documentPicker, animated: true, completion: nil)
}
You can create a
UTTypefrom a file extension like this:This creates a
UTType?, as there can be noUTTypeassociated with the given file extension.You can also use:
but this only finds a
UTTypeif the file extension inherits frompublic.data, so it won't work for all the file extensions.On macOS Terminal, you can also use the
mdlscommand to inspect the Uniform Type Identifier of a fileOr its entire tree:
After that you can create a
UTTypeusing its identifier like this: