我正在嘗試打開一個僅允許某些檔案型別的選擇器。我正在使用此檔案來查找我需要的 UTTYpe:https : //developer.apple.com/documentation/uniformtypeidentifiers/uttype/system_declared_uniform_type_identifiers
但我找不到 .pages、.doc、.docx 的 UTTYpe 例如......
我該怎么辦?
這是我目前的代碼
func presentPickerDocument() {
//Create a picker specifying file type and mode
var supportedTypes: [UTType]
supportedTypes = [UTType.pdf, UTType.url]
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
present(documentPicker, animated: true, completion: nil)
}
uj5u.com熱心網友回復:
您可以UTType從這樣的檔案擴展名創建一個:
UTType(tag: "pages", tagClass: .filenameExtension, conformingTo: nil)
這將創建一個UTType?,因為不能UTType與給定的檔案擴展名關聯。
您還可以使用:
UTType(filenameExtension: "pages")
但這只會UTType在檔案擴展名繼承自 時找到 a public.data,因此它不適用于所有檔案擴展名。
在 macOS 終端上,您還可以使用該mdls命令檢查檔案的統一型別識別符號
mdls -name kMDItemContentType yourFile.pages
或者它的整個樹:
mdls -name kMDItemContentTypeTree yourFile.pages
之后,您可以UTType使用其識別符號創建一個,如下所示:
UTType("com.apple.iwork.pages.sffpages")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/369292.html
標籤:迅速 文件 类型 uidocumentpickerviewcontroller 类型
上一篇:如何在Jetpackcompose中檢測Horizo??ntalPager中的滑動?
下一篇:Java按名稱和擴展名過濾檔案
