0

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...

Roshan
  • 712
  • 4
  • 17

2 Answers2

1

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)
iParesh
  • 2,338
  • 1
  • 18
  • 30
  • ok @iParesh so you are saying `storeurl ` will contain the pdf file..? –  May 16 '18 at 11:50
  • ok..so can u maybe suggest how I can do it..i.e. how do I store my `self.appDelegate.HTMLContent` in `storeUrl`..? –  May 16 '18 at 11:52
  • Here is link may be help you https://stackoverflow.com/questions/33503211/create-and-store-pdf-document-programmatically-using-swift-for-ios – iParesh May 16 '18 at 11:56
  • 1
    I am storing the pdf file that I created on the code, on NSDocumentDirectory with "NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)" but I cant share the file on whatsapp. It gives a warning like that this type of file cant be shared and closes the activitycontroller. – Kaan Esin Sep 28 '18 at 07:01
0

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)
Catherine
  • 654
  • 5
  • 15