简体   繁体   中英

iOS UIDocumentInteractionController PDF sharing issue

I want to share saved PDF in app. actually it was not working on PRINT and also on MAIL it was working with sharing over Whatsapp and other app.

{
    let fileManager = FileManager.default
    let imagePAth = (Common.getDirectoryPath() as NSString).appendingPathComponent("invoice.pdf")
    if fileManager.fileExists(atPath: imagePAth){
        let url = URL (fileURLWithPath: localurlfile)
        docController = UIDocumentInteractionController.init(url: url)
        docController.presentOptionsMenu(from: self.view.frame, in: self.view, animated: true)
    }else{
        print("No Image")
    }
}

You can share contents using UIActivityViewController.

if let pdfFileUrl = URL(String("yourFileURL")) {
let vc = UIActivityViewController(activityItems: [pdfFileUrl], applicationActivities: [])
present(vc, animated: true)`enter code here`

}

Refer this for more info. Use of UIActivityViewController and UIActivityItemProvider to share PDF

To view and sharing purpose.

let controller = UIDocumentInteractionController(url: pdfurl)
controller.delegate = self
controller.presentPreview(animated: true)

And implement UIDocumentInteractionControllerDelegate.

extension ViewController: UIDocumentInteractionControllerDelegate {
    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return self
    }

    func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM