【问题标题】:how to get iphone device local stored document [pdf,docx,doc,xlsxl] in swift如何快速获取 iphone 设备本地存储的文档 [pdf,docx,doc,xlsxl]
【发布时间】:2018-10-31 00:53:49
【问题描述】:

使用 UIDocumentPickerViewController 使用 icloud 获取所有文件[pdf,docx,doc,xlsxl,image]。这是我的代码

 @IBAction func uploadNewResumeAction(_ sender: Any) {
 let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.text", "com.apple.iwork.pages.pages", "public.data"], in: .import)
        documentPicker.delegate = self
        present(documentPicker, animated: true, completion: nil)
}


extension SchoolRulesView: UIDocumentPickerDelegate{

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
        let cico = url as URL
        print(cico)
        print(url)
        print(url.lastPathComponent)
        print(url.pathExtension)
    }
}

在某些情况下只想显示一个文件 docx,pdf,xlsxl,images。怎么可能?

还想获取iphone本地存储的.docx文件[例如:android手机本地存储文件显示上传]。

同样想获取所有 iphone 存储的本地文档并上传到服务器。怎么能成就我。提前帮我谢谢。

【问题讨论】:

    标签: ios swift image local-storage uidocumentpickerviewcontroller


    【解决方案1】:

    您应该使用 UTI 来定义允许的内容类型。完整列表可用here

    PDF、Microsoft Word、Microsoft Excel、PNG 和 JPEG 示例:

    let documentTypes = [kUTTypePDF as String, "com.microsoft.word.doc", "com.microsoft.excel.xls", kUTTypePNG as String, kUTTypeJPEG as String]
    let documentPicker = UIDocumentPickerViewController(documentTypes: documentTypes, in: .import)
    

    【讨论】:

    • UIDocumentMenuViewController 已弃用,请停止使用。请改用 UIDocumentPickerViewController。
    • 确实,我根据这个弃用编辑了答案,谢谢指出。
    • 如何在 iclouds 中仅获取 docx 文件帮助我
    • 如何只显示 xlsx 文件
    • docx 文件的 UTI 是 org.openxmlformats.wordprocessingml.document。对于 xlsx,org.openxmlformats.spreadsheetml.sheet(请参阅 Apple 的文档或 docx / xlsx 文件中 mdls 的输出)。
    【解决方案2】:

    有多个问题混合在一起......

    • 您对 UIDocumentPickerViewController 的使用看起来是正确的。例如,如果您只想选择 Word 文档,您确实可以自定义 UTI 列表。

    • 要预览文件,可以使用 QLPreviewController

    • UIDocumentPickerViewController 可用于 iCloud(和其他云服务)和本地存储(文件应用程序的“在我的 iPhone 上”部分)

    • 出于隐私原因,无法上传“所有”文档。但是您可以要求用户在选择器中选择他们要上传的所有文档。

    【讨论】:

    • 如何使用 UTI 在 iclouds 中仅获取 docx 文件帮助我
    • 使用 UIDocumentPickerViewController。 docx 文件的 UTI 是 org.openxmlformats.wordprocessingml.document(请参阅 Apple 的文档或 docx 文件中 mdls 的输出)。
    • 另请注意,“在我的 iPhone 上”部分仅在您的应用程序使用设备上的本地存储时才会出现。如果您没有使用本地存储的应用程序,则不会出现此选项
    猜你喜欢
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    相关资源
    最近更新 更多