我正在使用UIDocumentPickerViewController构建文件选择器,我只想选择以下文件类型(需要禁用其他文件类型),
到目前为止,我的代码如下,
import UIKit
import MobileCoreServices
class DocumentPickerVC: UIViewController {
@IBAction func btnLocalTapped(sender: UIButton) {
let types: [String] = [kUTTypeText as String, kUTTypePDF as String, "com.microsoft.word.doc", "org.openxmlformats.wordprocessingml.document"]
let documentPicker = UIDocumentPickerViewController(documentTypes: types, in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
documentPicker.allowsMultipleSelection = true
self.present(documentPicker, animated: true, completion: nil)
}
}
extension DocumentPickerVC: UIDocumentPickerDelegate {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
// you get from the urls parameter the urls from the files selected
for url in urls {
print(url)
}
}
}
我似乎无法弄清楚Google文档的UTCoreType是什么。
作为第二次尝试找到UTCoreType的尝试,我尝试了以下操作,
通过如下更改类型来使为选择器解锁的所有文件,
让类型= [kUTTypeItem作为字符串]
使用选择器下载文件并将其移至文档目录
启用iTunes文件共享并复制到我的桌面
针对文件运行“ mdls”工具
命令:
$ mdls doc2.gdoc
输出:
kMDItemContentCreationDate = 2018-10-15 23:07:02 +0000
kMDItemContentCreationDate_Ranking = 2018-10-15 00:00:00 +0000
kMDItemContentModificationDate = 2018-10-15 23:07:05 +0000
kMDItemContentType = "dyn.ah62d4rv4ge80s3dtqq"
kMDItemContentTypeTree = (
"dyn.ah62d4rv4ge80s3dtqq",
"public.data",
"public.item"
)
kMDItemDateAdded = 2018-10-15 23:07:12 +0000
kMDItemDateAdded_Ranking = 2018-10-15 00:00:00 +0000
kMDItemDisplayName = "doc2.gdoc"
kMDItemFSContentChangeDate = 2018-10-15 23:07:05 +0000
kMDItemFSCreationDate = 2018-10-15 23:07:02 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = (null)
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = (null)
kMDItemFSLabel = 0
kMDItemFSName = "doc2.gdoc"
kMDItemFSNodeCount = (null)
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 16848
kMDItemFSTypeCode = ""
kMDItemInterestingDate_Ranking = 2018-10-15 00:00:00 +0000
kMDItemKind = "Document"
kMDItemLogicalSize = 16848
kMDItemPhysicalSize = 20480
现在我没主意了。有什么想法吗?