How can I add a PDF file for an app , where you click on a button to view the file & when you\'re done you get back to screen you were at?
SWIFT 5
An update to open the file from the Document directory (device) and present preview:
let urlFile = URL(string: pathToFile)
var documentInteractionController: UIDocumentInteractionController!
self.documentInteractionController = UIDocumentInteractionController.init(url: urlFile!)
self.documentInteractionController?.delegate = self
self.documentInteractionController?.presentPreview(animated: true)
And UIDocumentInteractionControllerDelegate:
extension ViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
}
If you want to dismiss the document preview you can use:
self.documentInteractionController?.dismissPreview(animated: true)