How do I restrict UIDocumentPicker from adding .sh executable files in iOS 14.0 swift?

560 Views Asked by At

Currently using [.plainText, .spreadsheet, .html, .pdf, .xml, .presentation, .jpeg, .bmp, .gif, .png, .tiff, .content] these UTTypes but still able to attach .sh type files , how do I restrict executable files by still supporting text and doc files.

Also UTType doesn't specify type for .doc, .docx files

1

There are 1 best solutions below

0
On

I am not sure if you can restrict .sh file types considering that it is probably allowed when you accept plain text. Regarding the doc file type you can extend UTTType and implement your own .doc and .docx types:

import UniformTypeIdentifiers

extension UTType {

    static let doc: Self = .init(filenameExtension: "doc")!
    static let docx: Self = .init(filenameExtension: "docx")!

    static let xls: Self = .init(filenameExtension: "xls")!
    static let xlsx: Self = .init(filenameExtension: "xlsx")!

    static let ppt: Self = .init(filenameExtension: "ppt")!
    static let pptx: Self = .init(filenameExtension: "pptx")!

}

UTType.doc   // com.microsoft.word.doc
UTType.docx  // org.openxmlformats.wordprocessingml.document

UTType.xls   // com.microsoft.excel.xls
UTType.xlsx  // org.openxmlformats.spreadsheetml.sheet

UTType.ppt   // com.microsoft.powerpoint.ppt
UTType.pptx  // org.openxmlformats.presentationml.presentation