本文介绍了iOS上使用的UTImportedTypeDeclarations和UTExportedTypeDeclarations是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在这里遇到错字还是在iOS上确实存在两种变化:

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

  • UTImportedTypeDeclarations
  • UTExportedTypeDeclarations

两者都在Google上返回了一些结果,但是后者返回的点击数是原来的两倍.这些plist键有什么用?和 CFBundleDocumentTypes 有什么区别?CFpundBundleDocumentTypes 似乎已经做了我认为另外两个的工作,即允许应用打开特定文件类型?

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?

推荐答案

UTExportedTypeDeclarations

您使用 UTExportedTypeDeclarations 定义您自己的UTI ,您的应用程序希望以此来指导其安装系统.UTI描述一段数据(不一定是文件内的数据!),并且至少需要一个标识符( com.example.MyCoolDataType ).此外,它可能具有名称( My Cool Data Type ),一个或多个文件扩展名( .myCoolDataType ),一种或多种MIME类型( x-application/my-cool-data-type ),一种或多种粘贴板类型(在使用复制和粘贴传输此类数据时使用)和一种或多种旧式OS类型(四种字符代码,OS X不使用)不再是MacOS 9和更早版本的类型系统).通常,您还希望UTI符合现有的UTI,这样,不知道您的UTI但知道它所符合的UTI之一的应用仍然可以对它进行有意义的操作.例如.当您说您的UTI符合 public.data 时,可以处理通用数据的任何进程也可以处理您的UTI,因为您的UTI描述了通用数据.

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.

系统具有所有已知UTI的数据库,并且当您的应用程序定义新的UTI时,这些新的UTI将自动添加到数据库中,因此对于整个系统都是已知的.请注意,您的应用定义了这些UTI并不意味着它也可以处理"包含此类数据的文件!

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 确实向系统介绍了您想在系统中知道但不是不是您的UTI的UTI .这些值与 UTExportedTypeDeclarations 的值相同,所有类型也都添加到数据库中,因此在整个系统中都是可见的.

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.

UTExportedTypeDeclarations UTImportedTypeDeclarations 之间的区别仅在于您在 UTExportedTypeDeclarations 中声明了对UTI的所有权,这意味着系统是否已经知道UTI但存储的值与您的值不同,因为您的值是UTI,所以您的值会更新存储的值,因此您的描述始终被视为权威!如果是 UTImportedTypeDeclarations ,则对于系统已经知道的类型,甚至都不会查看这些内容,因为您所说的内容不具有权威性.到目前为止,仅考虑了未知类型的这些类型,并且一旦任何应用在 UTExportedTypeDeclarations 下列出了相同的UTI,该应用的值就会覆盖您的应用提供的值.

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.

典型用法示例:
您的应用程序能够读取另一个应用程序的专有数据格式,但您不知道该应用程序是否已安装在系统上.为了使该数据格式已知,您将其声明为import,因为一旦用户安装了该应用程序,您就希望该应用程序为您正确定义数据格式.

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 告诉系统您的应用程序可以打开哪些文档类型.除非您还在此处列出您的UTI,否则这些UTI在Finder中不会与您的应用程序相关联,并且您的应用程序不会出现在打开方式> 菜单中.如果将所有文件类型都定义为UTI,那么为每种文档类型提供的所有内容就是UTI和角色.如果未由文档类型覆盖,则名称,图标,文件扩展名或MIME类型之类的内容都将从UTI中获取.但是请注意,可以在不定义UTI的情况下定义文档类型,在这种情况下,必须直接在文档类型上设置所有这些值.您始终必须为文档类型设置的唯一角色是角色.该角色可以是查看者"(您可以显示该文件类型,但不能对其进行编辑),编辑器"(您可以显示和编辑该文件类型),无"(未指定该文件的功能).

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).

典型用法示例:
您希望您的应用与某些文件类型相关联,这些文件类型可以通过扩展名,MIME类型或UTI标识符来标识.如果您希望您的应用程序与UTI类型相关联,则该应用程序应导入或导出该类型,否则系统可能无法识别该类型,而注册为未知的UTI类型根本没有任何作用.

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.

这篇关于iOS上使用的UTImportedTypeDeclarations和UTExportedTypeDeclarations是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 14:50