3

我正在使用 UIDocumentPickerViewController 构建文件选择器,我只想选择以下文件类型(其他需要禁用),

  • 文档
  • 文档
  • pdf
  • 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)
    }
}

}

我似乎无法弄清楚 Google 文档的 UTCoreType 是什么。

我浏览了这里找到的列表https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html,但没有运气。

作为寻找 UTCoreType 的第二次尝试,我尝试了以下操作,

  1. 通过如下更改类型为选择器解锁所有文件,

    让类型 = [kUTTypeItem 作为字符串]

  2. 使用选择器下载文件并将其移动到文档目录

  3. 启用 iTunes 文件共享并复制到我的桌面

  4. 对文件运行“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
  1. 尝试了文件的 kMDItemContentType 但没有用

现在我没有想法。有什么想法吗?

4

0 回答 0