5

I am using document picker for picking documents and upload on Server. All I need to pass some extension for the allowed documents, But I am not able to find out what extension represents to what type of document. Here is a list of extensions I want to allow. - docx - Microsoft Word - xlsx - Microsoft Excel - pptx - Microsoft Powerpoint - pdf - csv - pages - numbers - key - Keynote - rtf - txt i know some extensions like "kUTTypePDF,kUTTypeRTF", but not all please help.

3 Answers 3

7

Swift 5.0

let types = [kUTTypePDF, kUTTypeText, kUTTypeRTF, kUTTypeSpreadsheet] // You can add more types here as pr your expectation
let importMenu = UIDocumentPickerViewController(documentTypes: types as [String], in: .import)

Try this one

If you want to select all files then you have to use following code:

let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content"], in: .import)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Nikunj, But i want only selected files (- docx - Microsoft Word - xlsx - Microsoft Excel - pptx - Microsoft Powerpoint - pdf - csv - pages - numbers - key - Keynote - rtf - txt).
6

For .doc, .docx, you can use "com.microsoft.word.doc", "org.openxmlformats.wordprocessingml.document"

For .xlsx, you can use "org.openxmlformats.spreadsheetml.sheet"

For .xls, you can use "com.microsoft.excel.xls"

Comments

4

Apple has posted a list of the built-in document types here:

https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

I believe that should have all the ones you are looking for. If not, then you'll have to add your own types. You can do this by selecting the Project in Xcode and going into the Info tab. Then at the bottom, add a new Imported UTI for each file type.

  • Description: User-friendly description
  • Identifier: This is the identifier you will use in the documentTypes parameter for UIDocumentPickerViewController. com.yourcompany.yourproduct.fileextension or similar.
  • Conforms to: "public.data, public.content"

Then under Additional Imported UTI properties click to add the following:

UTTypeTagSpecification (Dictionary)
    public.filename-extension (Array)
        Item 0 (String): the file extension without "." (i.e. "csv")

1 Comment

In Xcode 12 the section is called "Imported Type Identifiers"

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.