无法在社交媒体中分享PDF

时间:2018-02-20 06:23:07

标签: swift pdf uiactivityviewcontroller

当我尝试共享文本时,我获得了iPhone中可用的所有应用程序,但当我尝试共享PDF时,唯一可见的选项是Mail和Whatsapp。共享FB选项不存在。即使大小为86KB,我也无法在Whatsapp中共享PDF。我收到以下错误

“此商品无法共享。请尝试共享其他商品”

在以下链接中,可以在FB上分享它。

How to Share PDF file in all eligable and appear iOS app?

任何人都可以给我一些想法吗?我尝试了以下代码

func actionMenuViewControllerShareDocument(_ actionMenuViewController: ActionMenuViewController) {

    self.dismiss(animated: true, completion: nil)

    if let lastPathComponent = pdfDocument?.documentURL?.lastPathComponent,

       let documentAttributes = pdfDocument?.documentAttributes,
       let attachmentData = pdfDocument?.dataRepresentation() {
       let shareText = attachmentData
       let activityViewController = UIActivityViewController(activityItems: [shareText], applicationActivities: nil)
       self.present(activityViewController, animated: true, completion: nil)
    }
}

1 个答案:

答案 0 :(得分:1)

我使用了UIDocumentInteractionController而不是UIActivityViewController。以下代码解决了我向Whatsapp发送PDF,添加到Notes,Mail等问题。

let url = Bundle.main.url(forResource: "Sample", withExtension: "pdf")!
docController = UIDocumentInteractionController(url: url)
docController?.delegate = self
docController?.presentOptionsMenu(from: self.view.frame, in:self.view, animated:true)