8

I am creating an app in which there are custom file types such as .xyz file, which is not part of UTType API.

Here are the case problems:

  • I want to create a custom UTType with xyz extension.
  • While opening file app, only those file should be enable which has extension .xyz
  • The file with xyz extension should show a custom icon on file App.
Mont-iOS
  • 118
  • 1
  • 5
  • 1
    You can make your own UTIs. See [this](https://stackoverflow.com/questions/24958021/document-types-vs-exported-and-imported-utis) and [this](https://developer.apple.com/documentation/uikit/view_controllers/adding_a_document_browser_to_your_app/setting_up_a_document_browser_app). – Sweeper May 23 '21 at 05:41
  • https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3601077-init – matt May 23 '21 at 05:58

1 Answers1

20

You should have mentioned the solutions you tried and it did not work for you.

By the way, there are few steps that you can follow:

Step 1. Create your document type in info.plist

  • Give the name of your file type such as xyz
  • Define the type identifier such as com.app.xyz
  • Define the file icon against the key CFBundleTypeIconFiles

enter image description here

Step 2: Define the exported type identifier in info.plist

  • Add the same identifier that we added while defining document type, i.e. com.app.xyz

  • define your extension xyz, XYZ

enter image description here

Step 3: Now while initialising UIDocumentPickerViewController, use the UTtype with identifier you declared in first two steps:

let xyzUTType = UTType("com.app.xyz")
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [xyzUTType], asCopy: true)
Wali Haider
  • 1,202
  • 1
  • 16
  • 23