Catherine
Catherine

Reputation: 682

Unable to share PDF in Social media

When I tried sharing a text, I got all the apps that are available in my iPhone but when I try to share PDF, the only options that are visible are Mail and Whatsapp. Sharing on FB option was not there. I am unable to share the PDF in Whatsapp also even though the size is 86KB. I got the following error

"This item can't be shared. Try sharing some other item"

In the following link, it is possible to share on FB it seems.

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

Can anyone give me some idea?. I tried the following code

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)
    }
}

Upvotes: 0

Views: 1058

Answers (1)

Catherine
Catherine

Reputation: 682

I used UIDocumentInteractionController instead of UIActivityViewController.The following code solved my issue in sending PDF to Whatsapp, Add to Notes, Mail,etc..

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)

Upvotes: 1

Related Questions