Both macOS and iOS applications use Uniform Type Identifiers (UTIs) to identify data types that can be shared. UTIs serve as a way for different applications to communicate what data types they can understand, allowing efficient and accurate transfer of information.
In this article, we will explore what UTIs are and how they are used in iOS and macOS applications. We provide a step-by-step guide on how to define a new UTI for your own applications.
What are Uniform Type Identifiers (UTIs)?
Uniform Type Identifiers (UTIs) are a system of identifying data types in macOS and iOS applications. UTIs were introduced in macOS 10.4 Tiger as a replacement for the older creator code system. The goal of UTIs is to provide a unified and standardized way for applications to recognize and identify data types.
A UTI is an alphanumeric identifier of a data type. For example, the UTI for a PNG image file is
public.png. UTIs are used to identify a wide variety of data types, including images, audio files, videos, text documents, and more.
UTIs are hierarchical, meaning that a UTI can be a more specific version of another UTI. For example, the UTI for a JPEG image file is
public.jpeg, which is a sub-type of
public.image. This hierarchy allows applications to recognize and work with related data types.
UTIs are used to identify data types when sharing information between applications, such as through files or through . For example, when a user shares an image from their Photos app to another app, the Photos app will provide the receiving app with the UTI for the image file. This allows the receiving app to properly handle the image file and display it to the user.
How are Uniform Type Identifiers (UTIs) used?
UTIs are used extensively to identify and handle different data types. Here are a few examples of how UTIs are used in different contexts:
- Sharing data between applications: When a user shares data (such as an image, video, or document) from one app to another, the sharing app provides the receiving app with the UTI for the data type. This allows the receiving app to properly handle the data and display it to the user.
- Launching applications: When an application is launched, it can register the UTIs that it can handle. This allows other applications to know which data types can be opened in the launching application.
- Copy and paste: When a user copies data (such as text, images, or files) to the pasteboard, the data is assigned a UTI. This allows other applications to properly handle the data when it is pasted.
- Document type registration: When an application creates a new document, it can specify the UTI for the document type. This allows other applications to recognize and open the document type.
- iCloud file syncing: When files are synced to iCloud, they are assigned a UTI to allow other devices to recognize and open the file type.
As you can see, UTIs are an essential part of data handling. By using a standardized system of identifying data types, applications can work together more efficiently and provide a better user experience.
How to define a new Uniform Type Identifier (UTI)
Now that we have a better understanding of what UTIs are and how they are used in iOS and macOS applications, let’s explore how to define a new UTI for use in your own applications.
Defining a new UTI involves a few steps, including choosing a UTI name, specifying the data type, and registering the UTI with the system. Here is a step-by-step guide to defining a new UTI:
Step 1: Choose a UTI name
The first step in defining a new UTI is to choose a name for it. The UTI name should be unique and descriptive of the data type it represents. Custom UTIs should be in a reverse-domain notation, prefixed by the domain name of the organization that creates it. For example, the UTI for a custom image type created by The Example Corporation might be
Step 2: Specify the data type
The next step is to specify the data type that the UTI represents. Data types can be specified using one or more of the following methods:
- Descriptive name: Decide how the UTI would be described to a user.
- File extensions: If the UTI represents a specific file type, you can specify the file extension(s) associated with that file type. For example, the UTI for JPEG images specifies the
- MIME types: If the UTI represents a data type that is transferred over the Internet, you can specify the MIME type(s) associated with it.
- Uniform Type Identifiers: If the new UTI represents a more specific type of another pre-existing UTI, you can specify one or more UTIs that the new UTI conforms to. For example, the UTI for a custom image type might be a sub-type of the
Step 3: Register the UTI
Once you have chosen a name and specified the data type, you need to register the UTI with the system. This involves adding the UTI into your application’s
Info.plist file. The key for this entry should be
UTExportedTypeDeclarations if your application or organization owns the UTI or
UTImportedTypeDeclarations if the application merely declares support for another application or another organization’s UTI. The value for the entry should be an array containing dictionaries, each defining a UTI.
Here is an example of what the entry might look like for a custom image type UTI:
<key>UTExportedTypeDeclarations</key> <array> <dict> <key>UTTypeIdentifier</key> <string>example.custom-image</string> <key>UTTypeDescription</key> <string>Example Corporation's Custom Image</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>customimage</string> </array> </dict> <key>UTTypeConformsTo</key> <array> <string>public.image</string> </array> <key>UTTypeReferenceURL</key> <string>https://developer.example.com/types/custom-image</string> <key>UTTypeIconFile</key> <string>custom-image-file.icns</string> </dict> </array>
A UTI definition should include the following keys:
UTTypeIdentifier– The unique string identifying the UTI.
UTTypeDescription– The user-visible description of the UTI.
UTTypeTagSpecification— Defines the file name extensions or MIME types associated with the UTI
UTTypeReferenceURL— Points to a webpage where people can read more about the UTI.
UTTypeConformsTo— An array of UTIs that the new UTI is a sub-type of.
Step 4: Use the UTI in your application
Once you have defined and registered the UTI, you can use it in your application to handle data of that type. For example, you might add support for copying and pasting custom image data in your application. To do this, you would add code to your application that checks for the custom image UTI when reading data from the pasteboard and handle the payload appropriately if it matches the UTI.
Uniform Type Identifiers (UTIs) are an essential part of data handling in macOS and iOS applications. Applications can work together more efficiently and provide a better user experience through a standard method to define data types. Defining a new UTI involves choosing a unique name, specifying the data type, and registering the UTI with the system. By following these steps, you can define your own UTIs for use in your applications and provide better integration with other applications in the ecosystem.
0 thoughts on “How to Define Your Own Uniform Type Identifier (UTI)”
You must log in to post a comment.