Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given a UTI (Uniform Type Identifier), find all types to which it conforms

I am writing an application that makes use of Uniform Type Identifiers. Specifically, I am calling UTTypeCreateAllIdentifiersForTag() and passing it various MIME types.

My hope was that this function (as distinct from UTTypeCreatePreferredIdentifierForTag()) would give me the most specific UTI as well as all the UTIs to which it conforms. This appears not to be the case -- it either returns a single UTI, or the secondary UTIs are spurious.

There is the UTTypeConformsTo() function defined in the same header file, but I'd prefer a function that returns an array of all the types to which this UTI conforms.

There appears to be hope for me, as MDItemCopyAttributeList() will return such a list. That said, it requires an MDItemRef, which can be created from either a file path or URL -- which isn't great. Sometimes my data is only stored in-memory and I only have a MIME type to go by.

Do I have to iterate through the entire database of UTIs to get this information or am I missing something?

like image 875
Sedate Alien Avatar asked Oct 11 '10 06:10

Sedate Alien


People also ask

What is a type identifier?

The type identifier is used to find an appropriate record in the type table which contains the description of the corresponding type structure. When the type description is found, the function performs interpretation of the application data value (when encoding) or the encoded data value (when decoding).

What is file UTI?

Uniform type identifiers (UTIs) provide a unified way to identify data handled within the system, such as documents, pasteboard data, and bundles.

What is UTI in ios?

Uniform Type Identifiers (UTIs) are Apple's method for identifying data types. UTIs use a reverse-DNS naming structure. UTIs support multiple inheritance, allowing files to be identified with any number of relevant types, as appropriate to the contained data.


1 Answers

I was indeed missing something: the very obvious solution. While I was trawling through the symbols exported by LaunchServices (and noticed the interesting, but private UTTypeCopyPedigree()), I was reminded of UTTypeCopyDeclaration(), which is defined.

UTTypeCopyDeclaration() is given a UTI and returns (as a CFDictionaryRef) the property list in which the UTI was defined. The object in this dictionary with key kUTTypeConformsToKey is either a CFArrayRef or CFStringRef. In the case of an array, one can recursively iterate until a base type is reached.

This is how I built up an inheritance tree for a given UTI. I hope this helps anyone else with the same issue.

like image 163
Sedate Alien Avatar answered Dec 28 '22 12:12

Sedate Alien