user8977455
user8977455

Reputation:

Not able to share pdf via whatsapp

I'm having an html data that is being converted to pdf. Now I want to share that pdf via whatsapp. I tried to achieve it like so...

  let pdfData = generatePDF(from: self.appDelegate.HTMLContent)

  let activityViewController:UIActivityViewController = UIActivityViewController(activityItems:  [pdfData], applicationActivities: nil)

self.present(activityViewController, animated: true, completion: nil)

But when I select the recipient for sending, get the message This item cannot be shared. Please select a different item But the sharing can be done via message app. The problem is with whatsapp.

Did refer this link also..Share PDF through WhatsApp

But it didn't help...

Upvotes: 0

Views: 2343

Answers (2)

iParesh
iParesh

Reputation: 2368

You can not pass direct data. You should store pdf file in document or temp directory and than pass url of pdf file.

let vc = UIActivityViewController(activityItems: [storeurl], applicationActivities: [])

self.present(vc, animated: true, completion: nil)

Upvotes: 1

Catherine
Catherine

Reputation: 682

Use DocumentInteractionController and your issue will be solved

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: 0

Related Questions