gpt4 book ai didi

swift - mailComposeViewController 与 PdfKit swift 中的 pdf

转载 作者:行者123 更新时间:2023-11-30 11:46:04 26 4
gpt4 key购买 nike

我有一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com