我正在使用Swift 5开发一个iOS应用程序,它将把纯文本转换成pdf格式。我想和Whatsapp应用程序共享pdf文件,但是我无法找到如何保存之前的pdf文件,然后是我用Whatsapp保存的文件的url。我怎么能这么做?
编辑:我正在把纯文本转换成pdf格式,我手里有pdf数据,我想把它保存到本地,并得到它的网址
发布于 2019-08-24 17:26:32
您必须使用UIDocumentInteractionController。
var interactionController: UIDocumentInteractionController!然后通过按钮(例如)可以打开控制器。
@IBAction func savePDF(_ sender: Any) {
self.interactionController = UIDocumentInteractionController(url: "http://website.com/title.pdf")
self.interactionController.delegate = self
self.interactionController.presentOpenInMenu(from: button.frame, in: view, animated: true)
}更新:
let title = "PDF Title"
guard let outputURL = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent(title).appendingPathExtension("pdf")
else { fatalError("URL not created") } // PDF url
pdfData.write(to: outputURL, atomically: true) // pdfData is your PDF file
self.interactionController = UIDocumentInteractionController(url: outputURL)
self.interactionController.delegate = self
self.interactionController.presentOpenInMenu(from: button.frame, in: view, animated: true)https://stackoverflow.com/questions/57639433
复制相似问题