Gmail应用程序将PDF转换为电子邮件无法使用PDFKIT在UIACtivityViewController上正常工作

发布于 2025-01-28 17:21:07 字数 2048 浏览 2 评论 0原文

当您与uiactivityViewController共享PDF时,遇到了一些PDFKIT问题,而Gmail不会正确地转换PDF文件,它在其他每个平台(邮件应用程序,Yahoo Mail,Outlook等)上均可正常工作

 if let pdfData = document.dataRepresentation() {
            print("Ran")
            let objectsToShare = [pdfData]
            let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
            activityVC.popoverPresentationController?.sourceView = self.shareBtn
            //activityVC.popoverPresentationController?.sourceRect = CGRect(x: 200, y: 200, width: 100, height: 100)
            activityVC.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY,width: 0,height: 0)
            //self.presentedViewController?.present(activityVC, animated: true)
            print("Print presented view")
            activityVC.isModalInPresentation = true
            self.present(activityVC, animated: true, completion: nil)
        }

。 net/qdayn.jpg“ rel =” nofollow noreferrer“>

解决方案:

 let temporaryFolder = FileManager.default.temporaryDirectory
    let fileName = "document.pdf" //whatever you want to call the file name
    let temporaryFileURL = temporaryFolder.appendingPathComponent(fileName)
    print("print: ", temporaryFileURL.path)


    let activityVC = UIActivityViewController(activityItems: [temporaryFileURL], applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.shareBtn
    //activityVC.popoverPresentationController?.sourceRect = CGRect(x: 200, y: 200, width: 100, height: 100)
    activityVC.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY,width: 0,height: 0)
    //self.presentedViewController?.present(activityVC, animated: true)
    print("Print presented view")
    activityVC.isModalInPresentation = true
    self.present(activityVC, animated: true, completion: nil)
    

Ran into some pdfkit issues when you share a PDF with UIActivityViewController and Gmail doesnt convert the PDF file properly it works on every other platform (Mail app, Yahoo Mail, Outlook, etc)

 if let pdfData = document.dataRepresentation() {
            print("Ran")
            let objectsToShare = [pdfData]
            let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
            activityVC.popoverPresentationController?.sourceView = self.shareBtn
            //activityVC.popoverPresentationController?.sourceRect = CGRect(x: 200, y: 200, width: 100, height: 100)
            activityVC.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY,width: 0,height: 0)
            //self.presentedViewController?.present(activityVC, animated: true)
            print("Print presented view")
            activityVC.isModalInPresentation = true
            self.present(activityVC, animated: true, completion: nil)
        }

Pdf file

SOLUTION:

 let temporaryFolder = FileManager.default.temporaryDirectory
    let fileName = "document.pdf" //whatever you want to call the file name
    let temporaryFileURL = temporaryFolder.appendingPathComponent(fileName)
    print("print: ", temporaryFileURL.path)


    let activityVC = UIActivityViewController(activityItems: [temporaryFileURL], applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = self.shareBtn
    //activityVC.popoverPresentationController?.sourceRect = CGRect(x: 200, y: 200, width: 100, height: 100)
    activityVC.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY,width: 0,height: 0)
    //self.presentedViewController?.present(activityVC, animated: true)
    print("Print presented view")
    activityVC.isModalInPresentation = true
    self.present(activityVC, animated: true, completion: nil)
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文