Document Types vs. Exported and Imported UTIs
Asked Answered
H

1

55

Can anyone explain to me the difference between Document Types, Exported UTIs and Imported UTIs in Xcode 5.1? I want to be able to have my app automatically detect file type based on file extension. Which of these three would I need to implement in order to do that?

Halflife answered 25/7, 2014 at 14:25 Comment(0)
G
131

You add a Document Type to register that your app can open that Document Type, this is simple when you select a known file type, but if the file type is not known, you must also define it in Imported UTIs. And if you are the defining your own File Type you must declare it in Exported UTIs and add that Document Type to be able to open it.

Examples:

I want to open a PDF, which is a known file type, so I just register it in Document Types.

I want to open an EPUB, which isn't a known file type, so I register it in Imported UTIs and in Document Types.

I want to open and register a type that I'm authoritative of, so I register it in Exported UTIs and in Document Types.

As for your second question, please note that defining a type using a Document Type will make your app appear in the "Open in" dialog, but not necessarily will make your app distinguish between which type of file your app is receiving, you must take care of handling that yourself. For example, let's say that your app is an image editor, and you registered both png and jpeg types, when the user wants to edit an image your app will receive the file but it won't be detecting which type is automatically, you'll have to process the file and respond to whatever type it is.

Some relevant links:

A related Question.

A very good but old tutorial on this topic

Gaucherie answered 13/1, 2016 at 20:53 Comment(14)
please, do you know what to do if my app is the only producer of the file? My app is not able to read (open) the file, but it produces (creates) it for usage with my embedded application extension. My scenario works fine, but I am not able to force ios to show an icon associated with the file ...Comparative
@user3441734: mmm, well I haven't developed something like what you describe, but, If the only issue you have is that the file icon doesn't show up I would recommend you to check the Exported UTis menu, and check that you selected the corresponding icon for your file type in the small and large icons field. If you did that and the icon still doesn't show up, then I think you should ask a new question and give us more details about your app.Gaucherie
I have two exported UTI (with both small and large icons in proper sizes). I have only one document type (for the file my app can read). My app extension could read the second one. Everything works, as expected. The missing part is an icon for exported UTI, which is not known (there is no icon for the file in an email attachment even though you can open the file from emails action menu with my app extension)Comparative
@Comparative Ok, I suggest you take a look at this question, according to the accepted answer there, you should put the icon name in the CFBundleTypeIconFile key in the CFBundleDocumentTypes array, not in the UTExportedTypeDeclarations array. Also maybe it's worth noting that the OP in that question is using an icns file type for his icons, you should use that type as well.Gaucherie
It is done .... But I could expose only one document type, which my app can open (read). I don't have trouble with this icon. I have trouble with the second file type, which only my app extension can read. Because there is no application able to open it, there is no icon .... That's realityComparative
@Comparative Have you tried defining the second Document Type in your application? that should make the Icon appear even if you are opening the file in your extension. If even that fails I would strongly suggest you to ask a new question so maybe the other users have other suggestions that could help you.Gaucherie
how to define the second document type, if the application creates the file, but is NOT able to open it? And we are in the beginning .... So, or so, thank you for reading my 'notes'Comparative
@Comparative Well as far as I understand, app extensions requiere to be bundled within an app, define your Document Type in the App that bundles the extension, even if it's only the extension the one that reads that Document Type, there shouldn't any problema doing that.Gaucherie
If I do that, my app will be listed in the action menu even though is not supported. This 'solution' works (icon is there) but is not acceptable :-(Comparative
@Comparative mmm, yeah you're right, that would happen. I've searched for a solution for your scenario, but I haven't found a solution that meets your requirements, I suggest you opening a new question, I think it could be helpful for others to have that question on the site and maybe someone knows how to achieve this. I'm sorry I couldn't help you, but if I ever find something that works for your requirements I'll let you know :)Gaucherie
Odd bug in 9.3 will not allow me to import - app crashesTorchier
In my app I am attempting to import a certain not-known file type (.sty) in a UIDocumentPicker but on my customer’s device files of that type are ghosted and cannot be opened. Does UIDocumentPicker also follow the document types and imported UTIs ?Underclothing
@Underclothing as far as I recall yes, they just need to have your app installed, and your app must register it in the imported UTIs. If it doesn't work with that, I suggest you open a new question for it.Gaucherie
It's sort of amazing that after all of this time, Apple still hasn't documented this stuff well / kept documentation up to date. This article too is a bit old but I found it very helpful in understanding the concepts: balancingrock.nl/cocoa/2019/03/27/document-types-and-utis.htmlBuffet

© 2022 - 2024 — McMap. All rights reserved.