Swift 使用UIDocumentPickerViewController选择Google文档
我正在使用UIDocumentPickerViewController构建一个文件选择器,我只想选择以下文件类型(其他文件类型需要禁用)Swift 使用UIDocumentPickerViewController选择Google文档,swift,google-docs,uidocumentpickerviewcontroller,Swift,Google Docs,Uidocumentpickerviewcontroller,我正在使用UIDocumentPickerViewController构建一个文件选择器,我只想选择以下文件类型(其他文件类型需要禁用) 医生 docx pdf gdoc(谷歌文档文件格式) 文本 rtf 到目前为止,我掌握的代码如下: import UIKit import MobileCoreServices class DocumentPickerVC: UIViewController { @IBAction func btnLocalTapped(sender: UIButto
- 医生
- docx
- gdoc(谷歌文档文件格式)
- 文本
- rtf
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)
}
}
}
我似乎不知道谷歌文档的UTCoreType是什么
我查了一下这里的名单,但没找到
作为第二次尝试查找UTCoreType,我尝试了以下方法:
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
现在我没有主意了。有什么想法吗?我认为谷歌的文件类型没有UTI。最好是在应用程序中声明一个新的UTI作为导入的UTI。