5

I'm having a problem importing a file from the cloud. I'm dealing with a custom filetype that I didn't actually create. So I don't know what the actual extension type is (for example com.example.pdf). The file ends in .toc, so is there a way I can only accept files that end in .toc?

For example something like this:

UIDocumentPickerViewController(documentTypes: [String("*.toc")], in: .import)

If this is not possible, is there a way to allow ANY file to be selected? From there I could just check the last 4 digits and let the user know that the file must end in .toc?

To try and get more information on what type of file this is, I have also ran the following command in terminal:

file -I filename.toc

Which returned:

filename.toc: text/html; charset=us-ascii

Because this says it's a "text/html" file I tried using:

UIDocumentPickerViewController(documentTypes: [String(kUTTypeText)], in: .import)

However, this didn't allow me to select the file... Does anyone have any ideas?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Logan
  • 1,047
  • 10
  • 33

1 Answers1

3

kUTTypeText is for text/plain. You want kUTTypeHTML for text/html.

iOS may not agree that "toc" files are text/html. You should probably add an appropriate "Exported UTI" to your Info.plist that defines an appropriate mime-type for the "toc" extension. Then use that mime-type with your UIDocumentPickerViewController.

See Uniform Type Identifiers Overview for details on setting up an exported UTI in your app.

If you want to allow any file, use kUTTypeItem.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • iOS may not agree that `toc` files are `text/html`. You should probably add an appropriate "Exported UTI" to your Info.plist that defines an appropriate mime-type for the "toc" extension. Then use that mime-type with your `UIDocumentPickerViewController`. – rmaddy Dec 05 '17 at 03:09
  • Do you have a link that shows how to do this? I'm not familiar with the info.plist... Also, do you know if there is a way to just allow any file to be selected? That will be my last resort. – Logan Dec 05 '17 at 03:13
  • Okay, so I tried using kUTTypeData, but that looks like it works for all files except for my .toc file... So does this mean that iOS doesn't even look at the toc file as data? – Logan Dec 05 '17 at 03:25
  • Try `kUTTypeItem`. If that doesn't work, nothing will (at least until you add an exported UTI for the "toc" extension. – rmaddy Dec 05 '17 at 03:27
  • That did it, I will mark your answer as the correct answer, but for future viewers do you mind just adding that to your answer as well? – Logan Dec 05 '17 at 03:28