swift - mailComposeViewController 与 PdfKit swift 中的 pdf

标签 swift mfmailcomposeviewcontroller pdfkit

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

相关文章:

ios - MFMailComposeViewController 的 UINavigationBar 不一致地显示正确的图像/颜色

ios - 在 Objective-C 上设置电子邮件标题?

node.js - 在 Node js中使用pdfkit指定PDF页面大小

css - 在浏览器窗口中预览@page 渲染

swift - for-case 模式匹配中枚举元素的索引

macos - 操作系统: Track mouse position when not the key application

ios - Swift ios 不确定如何在使用 Storyboard id 时将导航栏添加到 Storyboard 中的 VC

iphone - 带有收件人显示名称和电子邮件地址的 MFMailComposeViewController

ios - 如何在ios13中禁用pdfkits pdfview中的查找、共享、转发菜单项

swift - 需要了解闭包中的执行顺序