How to open file in iOS?

后端 未结 1 1386
挽巷
挽巷 2021-01-22 09:24

I\'m trying to open a .pdf file after download which is downloaded with Alamofire. But I\'ve seen only using a \"webview\". Thus the application co

相关标签:
1条回答
  • 2021-01-22 09:34

    You should use UIDocumentInteractionController. You can read about it on this Apple documentation page.

    By doing some Googling you should see even some example implementations. For example here you can see some code about this done by "mattneub".

    I let you one more code that you can use:

    var documentInteractionController: UIDocumentInteractionController!
    
    @IBAction func openDocument(sender: UIButton) {
      let URL: NSURL = NSBundle.mainBundle().URLForResource("yourPDF", withExtension: "pdf")!
    
        if (URL != "") {
            // Initialize Document Interaction Controller
            self.documentInteractionController = UIDocumentInteractionController(URL: URL)
    
            // Configure Document Interaction Controller
            self.documentInteractionController.delegate = self
    
            // Present Open In Menu
            self.documentInteractionController.presentOptionsMenuFromRect(sender.frame, inView: self.view, animated: true)
                //presentOpenInMenuFromRect
        }
    }
    
    // UIDocumentInteractionControllerDelegate
    func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController {
        return self
    }
    
    0 讨论(0)
提交回复
热议问题