xcode 文档类型与导出和导入的 UTI
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24958021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Document Types vs. Exported and Imported UTIs
提问by NoodleOfDeath
Can anyone explain to me the difference between Document Types, Exported UTIs and Imported UTIs in Xcode 5.1? I want to be able to have my app automatically detect file type based on file extension. Which of these three would I need to implement in order to do that?
谁能向我解释 Xcode 5.1 中文档类型、导出的 UTI 和导入的 UTI 之间的区别?我希望能够让我的应用程序根据文件扩展名自动检测文件类型。为了做到这一点,我需要实施这三个中的哪一个?
回答by aldoram5
You add a Document Typeto register that your app can open that Document Type, this is simple when you select a known file type, but if the file type is not known, you must also define it in Imported UTIs. And if you are the defining your own File Type you must declare it in Exported UTIsand add that Document Typeto be able to open it.
您添加一个文档类型来注册您的应用程序可以打开该文档类型,当您选择已知文件类型时这很简单,但如果文件类型未知,您还必须在导入的 UTI 中定义它。如果您定义自己的文件类型,则必须在导出的 UTI 中声明它并添加该文档类型才能打开它。
Examples:
例子:
I want to open a PDF, which is a known file type, so I just register it in Document Types.
我想打开一个已知文件类型的 PDF,所以我只在Document Types 中注册它。
I want to open an EPUB, which isn't a known file type, so I register it in Imported UTIsand in Document Types.
我想打开一个 EPUB,它不是已知的文件类型,所以我在Imported UTIs和Document Types 中注册它。
I want to open and register a type that I'm authoritative of, so I register it in Exported UTIsand in Document Types.
我想打开并注册我授权的类型,所以我在Exported UTIs和Document Types 中注册它。
As for your second question, please note that defining a type using a Document Type will make your app appear in the "Open in" dialog, but not necessarily will make your app distinguish between which type of file your app is receiving, you must take care of handling that yourself. For example, let's say that your app is an image editor, and you registered both png and jpeg types, when the user wants to edit an image your app will receive the file but it won't be detecting which type is automatically, you'll have to process the file and respond to whatever type it is.
至于你的第二个问题,请注意使用 Document Type 定义类型会让你的应用出现在“打开方式”对话框中,但不一定会让你的应用区分你的应用接收的是哪种类型的文件,你必须采取照顾好自己。例如,假设您的应用程序是一个图像编辑器,并且您注册了 png 和 jpeg 类型,当用户想要编辑图像时,您的应用程序将收到该文件,但它不会自动检测哪种类型,您必须处理文件并响应它的任何类型。
Some relevant links:
一些相关链接: