我想在应用程序中共享保存的PDF.实际上它不适用于PRINT和MAIL,而是通过Whatsapp和其他应用程序共享。
{
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")
}
}
您可以使用UIActivityViewController共享内容。
if let pdfFileUrl = URL(String("yourFileURL")) {
let vc = UIActivityViewController(activityItems: [pdfFileUrl], applicationActivities: [])
present(vc, animated: true)`enter code here`
}
有关详细信息,请参阅此内容。 使用 UIActivityViewController 和 UIActivityItemProvider 共享 PDF
查看和共享目的。
let controller = UIDocumentInteractionController(url: pdfurl)
controller.delegate = self
controller.presentPreview(animated: true)
并实现UIDocumentInteractionControllerDelegate。
extension ViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
}
}