Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用UIDocumentPickerViewController选择Google文档_Swift_Google Docs_Uidocumentpickerviewcontroller - Fatal编程技术网

Swift 使用UIDocumentPickerViewController选择Google文档

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

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

  • 医生
  • docx
  • 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)
    }
}

}
我似乎不知道谷歌文档的UTCoreType是什么

我查了一下这里的名单,但没找到

作为第二次尝试查找UTCoreType,我尝试了以下方法:

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

    let types=[kUTTypeItem作为字符串]

  • 使用选择器下载文件并将其移动到documents目录

  • 启用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
    
  • 尝试了文件的kMDItemContentType,但不起作用

  • 现在我没有主意了。有什么想法吗?

    我认为谷歌的文件类型没有UTI。最好是在应用程序中声明一个新的UTI作为导入的UTI。