为什么 UTTypeCreatePreferredIdentifierForTag 返回奇怪的 UTI?

Why is UTTypeCreatePreferredIdentifierForTag returning strange UTI?

如果我调用这个

import UIKit
import MobileCoreServices
import Foundation

var fileExtension:CFString = "7z" as CFString
var unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, nil)?.takeRetainedValue();
print(unmanagedFileUTI)

我明白了

dyn.age8xs8u

作为结果。我没有找到关于 age8xs8u 的任何信息。这是 7z 的正确 UTI 吗?

这意味着“7z”文件扩展名不为 MobileCoreServices 框架所知,也未被任何已安装的应用程序注册。在这种情况下 UTTypeCreatePreferredIdentifierForTag() 创建并 return 一个临时 UTI:

If no result is found, this function creates a dynamic type beginning with the dyn prefix. This allows you to pass the UTI around and convert it back to the original tag.

函数 returns nil 仅当 inTagClass 参数无效时。 使用有效的标签 class 参数,对于任意文件标识符,您总是会得到一个 UTI。

您可以检查 return 值是否有前缀 "dyn." 以检查 如果 returned UTI 是动态创建的 UTI 或已注册的 UTI。

根据 https://en.wikipedia.org/wiki/7z,7z 文件的 UTI 格式为 "org.7-zip.7-zip-archive".