How to open the Document files e.g(.pdf,.doc,.docx) in ios mobile when a button action using swift3.0?

后端 未结 3 1764
我在风中等你
我在风中等你 2020-12-05 05:15

I need to open UIDocumentPickerViewController and It should allow user to select all type of files. ie.(.pdf,.doc)files I used UIDocumentPickerViewControl

3条回答
  •  没有蜡笔的小新
    2020-12-05 06:01

    Swift 3*, 4*,

    To open document and select any document, you are using UIDocumentPickerViewController then all documents presented in your iCloud, Files and in Google Drive will be shown if Google Drive is connected in user device. Then selected document need to download in your app and from there you can show it in WKWebView,

       @IBAction func uploadNewResumeAction(_ sender: Any) {
    
      /*  let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item","public.data", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content", "public.text"], in: .import) */
    
        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 YourViewController: UIDocumentPickerDelegate{
    
    
          func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    
                    let cico = url as URL
                    print(cico)
                    print(url)
    
                    print(url.lastPathComponent)
    
                    print(url.pathExtension)
    
                   }
       }
    

    Note: If you intend to select all files the you have to use following code:

      let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item","public.data", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content", "public.text"], in: .import) 
    

    In your action method.

提交回复
热议问题