1

Using UIDocumentPickerViewController got all the files[pdf,docx,doc,xlsxl,image] using icloud. Here my code

 @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)
    }
}

In some scenario want to display only one file docx,pdf,xlsxl,images.How it possible?

Also want to get iphone local stored .docx file [Ex: android phone local store file diplay to upload].

Same want to get the all the iphone stored local document and upload to server. how can achieve me. help me thanks advance.

saravanar
  • 639
  • 2
  • 11
  • 25

2 Answers2

2

You should use UTIs to define allowed content types. Full list is available here.

Example with PDF, Microsoft Word, Microsoft Excel, PNG and 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)
Thomas
  • 449
  • 3
  • 7
1

There are multiple questions mixed together....

  • Your usage of UIDocumentPickerViewController looks correct. You can indeed customize the list of UTIs if you want to select, for example, only Word documents.

  • To preview a file, you can use QLPreviewController

  • UIDocumentPickerViewController can be used both for iCloud (and other cloud services) and local storage (the « on my iPhone » section of the Files app)

  • It is not possible to upload « all » documents for privacy reasons. But you can ask the users to select all the documents they want to upload in the picker.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15
  • how can get only docx file in iclouds using UTI help me – saravanar Oct 17 '18 at 11:24
  • Use a UIDocumentPickerViewController. The UTI for docx files is `org.openxmlformats.wordprocessingml.document` (see Apple's documentation or the output of `mdls` on a docx file). – Thomas Deniau Oct 18 '18 at 12:07
  • Also note that the "on my iPhone" section will only appear if you have apps that make use of the local storage on your device. If you have no apps that make use of local storage then this option will not appear – SilentK Feb 25 '19 at 10:27