我有一个 Swift 中带有 PdfKit 的 pdf 文件的代码
但是电子邮件无法打开应用程序内我没有收到任何错误
let mailComposeViewController = MFMailComposeViewController()
if let lastPathComponent = pdfDocument?.documentURL?.lastPathComponent,
let documentAttributes = pdfDocument?.documentAttributes,
let attachmentData = pdfDocument?.dataRepresentation() {
if let title = documentAttributes["Title"] as? String {
mailComposeViewController.setSubject(title)
}
mailComposeViewController.addAttachmentData(attachmentData, mimeType: "application/pdf", fileName: lastPathComponent)
}
最佳答案
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
var documentsDirectory: String = paths[0]
var finalPath: String = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("myPdf.pdf").absoluteString
print("\(finalPath)")
var error: Error? = nil
var myData = Data(base64Encoded: pdfContent, options: [])
var url = URL.fileURL(withPath: finalPath)
if error != nil {
print("Fail: \(error?.localizedDescription)")
}
var mailComposer = MFMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
mailComposer.mailComposeDelegate = self
mailComposer.addAttachmentData(myData!, mimeType: "application/pdf", fileName: "myPdf.pdf")
self.present(mailComposer, animated: true, completion: nil)
}
关于swift - mailComposeViewController 与 PdfKit swift 中的 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48824407/