What are UTImportedTypeDeclarations and UTExportedTypeDeclarations used for on iOS?
Asked Answered
P

2

20

Am I facing a typo here or do really both variations exist on iOS:

  • UTImportedTypeDeclarations
  • UTExportedTypeDeclarations

Both return some results on Google, however the latter one returns twice as many hits. What are these plist keys used for? And what is the difference to CFBundleDocumentTypes which already seems to do what I think the other two do, namely allow an app to open specific file types?

Paraffin answered 21/2, 2014 at 15:7 Comment(0)
E
42

UTExportedTypeDeclarations

You use UTExportedTypeDeclarations to define your own UTIs that your app wants to teach the system it is installed on. An UTI describes a piece of data (not necessarily data located inside a file!) and requires at least an identifier (com.example.MyCoolDataType). Additionally it may have a name (My Cool Data Type), one or more file name extensions (.myCoolDataType), one or more MIME types (x-application/my-cool-data-type), one or more pasteboard types (used when transferring data of that kind using copy&paste), and one or more legacy OS types (four character codes, not used by OS X any longer, that was the type system of MacOS 9 and earlier). Usually you also want UTIs to conform to existing UTIs, that way apps that don't know your UTI but that do know one of the UTIs it conforms to is still able to perform meaningful operations on it. E.g. when you say your UTI conforms to public.data, any process that can deal with generic data can also deal with your UTI as your UTI describes generic data.

The system has a database of all known UTIs and when your application defines new UTIs, these are automatically added to the database and thus are known to the entire system. Please note that the fact, that your app defines these UTIs doesn't mean that it can also "handle" files containing data of that kind!

Typical usage example:
You define your own proprietary file data format and you want this data format to be also known to other apps, plugins, extensions, and so on.

UTImportedTypeDeclarations

You use UTImportedTypeDeclarations do teach the system about UTIs that you want to be known in the system but that are not your UTIs. The values are the same as for UTExportedTypeDeclarations and all the types are also added to the database and are thus visible throughout the entire system.

The difference between UTExportedTypeDeclarations and UTImportedTypeDeclarations is only that you claim ownership of the UTIs in UTExportedTypeDeclarations, which means if the system already knows that UTI but the stored values are different than your values, your values update the stored values, as it is your UTI, so your description is always considered authoritative! In case of UTImportedTypeDeclarations, these are not even looked at for types already known to the system as what you say is not authoritative. These are only taken into account for types unknown so far and as soon any app lists the same UTIs under UTExportedTypeDeclarations, the values of that app override the values given by your app.

Typical usage example:
Your app is able to read the proprietary data format of another application, yet you don't know if that application is even installed on the system. To make that data format known, you declare it as import, since as soon as the user installs the app in question, you want that this app correctly defines the data format for you.

CFBundleDocumentTypes

You use CFBundleDocumentTypes to tell the system which Document types your app is able to open. Unless you also list your UTIs here, these UTIs are not associated with your app in Finder and your app won't appear in the Open With > menu. If you defined all your file types as UTIs, then all you need to provide for every document type is the UTI and the role. Things like the name, the icon, the file extensions, or the MIME types will all be taken from the UTI if not overridden by a document type. Note however, that you can define document types without defining an UTI, in that case you must set all these values directly on the document type. The only thing you always must set for a document type is the role. The role can be "Viewer" (you can display that file type but you cannot edit it), "Editor" (you can display and edit that file type), "None" (it's not specified what you can do with that file).

Typical usage example:
You want your app do be associated with certain file types, identified either by extension, by MIME type, or by UTI identifier. If you want your app to be associated with an UTI type, the app should either import or export the type, as otherwise the type may not be known to the system and registering to unknown UTI type has simply no effect at all.

Ehf answered 22/6, 2018 at 17:49 Comment(1)
Thank you for taking the time to write this all down clearly! This is super helpful.Binge
B
12

You use UTExportedTypeDeclarations if your app defines new UTIs. This tells the system of your own custom UTIs.

You use UTImportedTypeDeclarations if your app uses UTIs created by others but aren't defined by the system.

Bonbon answered 21/2, 2014 at 15:41 Comment(6)
To do what with these UTIs?Paraffin
To reference them in your app. This could be used with UIDocumentInteractionController or indicating that your app should appear in another app's "Open In" menu for these types of files.Bonbon
I added CFBundleDocumentTypes to my app and that's enough to make my app show up in the "Open In" menu of other apps.Paraffin
CFBundleDocumentTypes is used to define what types of files your app can open. So yes, adding that will allow your app to appear in the "Open In" of other apps of they are sharing the type of file you registered for.Bonbon
I found a nice post: mobiforge.com/design-development/… It explains why CFBundleDocumentTypes is enough to get ones app show up in the "Open In" menu and what UTExportedTypeDeclarations is used for. In short: if the file type is "well known" you only ever need CFBundleDocumentTypesParaffin
@maddy You seem to know these things pretty well. Any thoughts on this one (related): stackoverflow.com/questions/21937731Paraffin

© 2022 - 2024 — McMap. All rights reserved.