Reputation: 374
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")
}
}
Upvotes: 0
Views: 338
Reputation: 383
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
Upvotes: 1
Reputation: 686
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) {
}
}
Upvotes: 0