Ios uti (Uniform type identifier) opens an APP Based on the file suffix

Source: Internet
Author: User
Tags arabic numbers list of attributes

Ios uti (Uniform type identifier) opens an APP Based on the file suffix

Preface

There is a need in the recent project to use the content sharing function provided by the iOS system on iOS devices to directly share entity content from a third-party App to our App. The general principle is as follows: first, we can enable document types (document type) for registration for our iOS app, and then in a third-party app, if they use the sharing feature provided by iOS, then we will see our application and click to share it. I will explain in detail the specific design and implementation of requirements in the next blog. This article describes a set of unified specifications provided by Apple in iOS and OS X systems to better identify types, that is, the "Uniform Type Identifier (UTI)" mentioned in the title. I translate it into a "unified Type Identifier", which is referred to as "UTI ".

Official tutorial

There are very few tutorials on the use of UTI on the Internet, so I just referred to the instructions provided by the official documentation of Apple. This blog is my understanding of the official documentation !! I will post the original official document to help you learn and understand it, so that it will not be misled by my mistakes, we also recommend that you search for some documents from the Developer Center. Here we recommend several articles:

1. Cocoa Core Competencies-Uniform Type Identifier?

This document provides a view to illustrate what the UTI is, how it works, and who it is used.

2. introduction and use of Uniform Type Identifier?

This document describes in detail the basic concepts and attributes of UTI, as well as their usage and rich content. This article mainly references this article.

3. System-Declared Uniform Type Identifiers?

This document provides a list of UTI defined in OS X. You can view the definitions and meanings of each officially provided UTI.

4. UTType Reference?

This document provides Function Methods for direct operations on the UTI string.

5. Add a custom document type and a new UTI for the iOS app step by step?

As the name suggests, this document explains how to import a new identifier and add a custom document type in the iOS app.

Why is there UTI?

For example, it is similar to how many countries in the world speak English as official languages. Why is this analogy true? Because Chinese people speak their mother tongue and French, but if a Chinese person arrives in France but does not understand French, the French he encounters do not understand Chinese, then, how can they communicate? This is the application of English. In contrast, Apple's operating system is equivalent to the whole world. Different programs or services are equivalent to different countries. Two different programs want to communicate with each other, such as sending files to each other, however, if one uses a file extension and the other uses the MIME type, the two have different data types and cannot be parsed. They do not know each other. How can they communicate with each other? In such a situation, UTI becomes useful, and serves as the English role of the real world.

Description

Uniform type identifiers (UTIs) provides a unified way to identify data throughout the system, such as documents, pasteboard data, and bundles ). According to the official document, the definition of UTI is as follows: "A uniform type identifier is a string that uniquely identifies a class of entities considered to have a 'type '.". Generally, a unified type identifier is a string that uniquely identifies an object with a "type" attribute. In addition, for this "type", the official document also provides an example to explain the Data type of a file or byte stream. For packages and bundles, "type" refers to their internal directory hierarchy.

Usage

In most cases, a UTI provides a unique identifier that all programs and services in the system can recognize and depend on. In this case, it may be too abstract, let's use the example given in the official document, for example, a JPEG image file. In different environments, there are several different identification methods:

1. 'jpeg ', OSType indicates,

2.'.jpg ', File Extension

3.jpeg, File Extension

4. One type in 'image/jpeg 'and MIME (multi-purpose Internet Mail Extension Type)

Utithen is identified by the 'public.jpeg 'string, Completely replacing these inconsistent tags. This string is completely compatible with any other old tag and can be converted between them. Because UTI can identify any type of entities, they are more flexible than the old tags. Using UTI, we can represent the following entities:

Pasteboard data

Folders (directories)

Bundles

Frameworks

Streaming data

Aliases and symbolic links

Usage

1. Introduction

Apple provides us with a set of UTI strings that are commonly used in iOS and Mac apps, such as 'public. data ', 'public. item ', 'public. image' and so on. We can refer to their meanings in official documents. In addition, we can also customize our own UTI string in the application. For example, we can define an UTI string that identifies the special document format as 'CC. icoc. shaobozheng, if other applications want to support our documents in this format, they can use 'cc. icoc. shaobozheng 'to identify our documents.

2. Character Set

The preceding example shows the character set used to define the UTI string. Typically, a UTI string is a Unicode string containing ASCII characters, and can also contain Roman letters and Arabic numbers, such as (A-Z), (a-z), (0-9) there is also a dot (". ") and connector ("-"). Any string containing invalid characters, such as the underscore '_', cannot be used as the identifier of the content, and Apple does not have any error feedback.

3. Syntax

Just like in my example above, the definition of UTI is the same as when we enter organization during iOS program development, and anti-domain rules are adopted. See the following:

Com. apple. quicktime-movie

Com. mycompany. myapp. myspecialfiletype

Public.html

Com. apple. pict

Public.jpeg

Domain names such as 'com' and 'public' in the UTI are only used to indicate the location of the UTI string at the domain name level, and will not affect any groups of similar types. For example, the 'public' domain name is used by most applications to identify the standard type. Currently, only Apple can create the 'public' Domain Name's UTI.

In addition, we may encounter a 'dyn' domain name, which is a dynamic domain name, which means that we are using it and will not specify this type of UTI as a string, then, the system will automatically identify and help us with the process. We cannot see such dynamic identifiers, but we can convert them to common types, such as OSType and MIME types, through the UTI string operation. The official document provides a metaphor for dynamic identifiers: "You can think of a dynamic identifier as a UTI-compatible wrapper around an otherwise unknown filename extension, MIME type, OSType, and so on ", which means we can use this dynamic identifier as a rewrite and packaging for common types, and it is a identifier compatible with UTI.

The last one is a customizable domain name, which is representative of the 'com 'domain name. Apple also provides us with some of the 'com' domain names they have defined.

Compliance

A key advantage of UTI over other old tags is that it can be declared in a compliant structure. In our object-oriented approach, UTI is extensible and multi-inheritance. First:

  

 

As shown in, 'public.html' is inherited from 'public.text', because 'public.html 'identifies HTML text format and text format, while text, images, and so on all belong to Data, so they inherit from 'public. 'data.

The above figure refers to the inheritance structure of the content form in the UTI. In principle, when you specify the UTI level, you can specify its functional structure, you can also specify its physical structure, which is a content structure diagram. the physical structure refers to the physical nature of the UTI. For example, it identifies a directory and a file, and the functional structure refers to the image of the UTI, such as a file, it identifies images, videos, and so on. Generally, the rules for specifying the UTI hierarchy are as follows:

1. a uti must inherit 'public. item' at the physical level'

2. At the functional level, a UTI must inherit UTI other than 'public. item.

However, it is not mandatory to specify the functional level of the UTI, but it is considered that the UTI can be better integrated into some features of the system, such as the Spotlight application, you can associate the specified functional UTI with the naming attribute. The following is a structure diagram of the UTI Functional Adaptation structure and physical adaptation:

  

 

This sequence makes our UTI more flexible in determining the type, not only avoiding the use of a large number of conditional judgments, but also associating some unexpected types.

Use UTI

Application scenarios

In Mac OS, we can often use UTI when developing applications. However, when developing iOS applications, there are not many scenarios where UTI is applied, this is also the reason why the number of online tutorials is low. In iOS development, we generally use UTI to identify the clipboard type. When using the UTI string provided by Apple, we must use the constant defined in the UTCoreTypes. h file to replace the string directly. For detailed usage of UIPasteboard, you can go to this blog to learn more: proficient in UIPasteboard clipboard.

Procedure

Now let's take a look at some of the methods provided by Apple to directly operate the UTI function. Here are a few simple examples. We can find it in the UIType. h file in the MobileCoreServices framework. We can also take a closer look at other files in the framework, all of which are definitions and lifecycles of UTI.

1. UITypeEqual

Determine whether the two Uris are exactly the same. The latter is a subset of the dynamic tag description that is another identifier description.

2. UITypeConformsTo

To determine the compliance of the two labels, we can use the object-oriented perspective to determine whether the labels are subclasses.

3. UTTypeCreatePreferredIdentifierForTag

You can use other types of identifiers, such as MIME identifiers, to convert them to UTI. When you can create multiple UTI strings, the UTI of the 'public' domain name is generally returned.

4. UTTypeCreateAllIdentifiersForTag

Convert other types of identifiers, such as MIME identifiers, to UTIs. When multiple UTIs strings can be created, all UTIs strings are returned, so that you can select

5. UTTypeCopyPreferredTagWithClass

Exchange the UTI string identifier

Custom UTI

Usage

Apple allows Mac developers to customize the new UTI for their Mac App's unique data format. They are generally declared in the following files:

Info. plist

Application bundles

Spotlight Importer bundles

Automator action bundles

Use the official party to give us an example of utideclaration. public.jpeg statement:

UTExportedTypeDeclarations

UTTypeIdentifier

Public.jpeg

UTTypeReferenceURL

Http://www.w3.org/graphics /;

UTTypeDescription

JPEG image

UTTypeIconFile

Public.jpeg. icns

UTTypeConformsTo

Public. image

Public. data

UTTypeTagSpecification

Com. apple. ostype

JPEG

Public. filename-extension

Jpeg

Jpg

Public. mime-type

Image/jpeg

List of attributes declared by a UTI statement:

Value type

Description

UTExportedTypeDeclarations

Array of dictionaries

An array of exported UTI declarations (that is, identifiers owned by the bundle's publisher ).

UTImportedTypeDeclarations

Array of dictionaries

An array of imported UTI declarations (that is, identifiers owned by another company or organization ).

UTTypeIdentifier

String

The UTI for the declared type. This key is required for UTI declarations.

UTTypeTagSpecification

Dictionary

A dictionary defining one or more equivalent type identifiers.

UTTypeConformsTo

Array of strings

The UTIs to which this identifier conforms.

UTTypeIconFile

String

The name of the bundle icon resource to associate with this UTI.

UTTypeDescription

String

A user-visible description of this type. You can localize this string by including it in an InfoPlist. strings file.

UTTypeReferenceURL

String

The URL of a reference document describing this type.

In addition, you must specify UTExportedTypeDeclarations or UTImportedTypeDeclarations for the custom UTI, so that all third-party apps can be used or imported to other bundle in the project that does not own the data format. In the official document, there is a saying: "If both imported and exported declarations for a UTI exist, the exported declaration takes precedence over imported one". What I understand is, the exported UTI declaration owner is the publisher who defines the UTI, and the imported UTI declaration owner is others. Therefore, if both types of declarations exist for an UTI, the exported UTI statement takes priority.

Suggestions for customizing UTI

1. Your UTI string must be unique. The anti-Domain Name naming method starting with 'com. 'is a simple and effective method to ensure uniqueness.

2. If your code depends on a third-party App, the UTI type may not be displayed in the system. You should declare it as the Import Type in the bundle.

3. If your UTI type is one or more existing UTI subclass, you must add compliance to it so that it inherits from a parent class. It is best to inherit from the 'public' type.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.