0

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)
    }
}
Catherine
  • 654
  • 5
  • 15
  • I don't think you can share PDFs to FB. Btw you should try to save the pdf data to a temporary directory and share its url – Leo Dabus Feb 20 '18 at 06:44
  • Oh...Other than mail, whatelse v can use to share? @LeoDabus – Catherine Feb 20 '18 at 06:45
  • As I said save it locally first. You can check the apps that would be available using QuickLook preview controller to preview the pdf and see what apps are available for sharing there – Leo Dabus Feb 20 '18 at 06:47
  • ok I will try. Thank u@LeoDabus – Catherine Feb 20 '18 at 06:48
  • Btw better to use url resourceValues method to get the resource localizedName instead of lastPathComponent https://stackoverflow.com/questions/28570627/how-to-find-file-uti-for-file-withouth-pathextension-in-a-path-in-swift/34772517#34772517 – Leo Dabus Feb 20 '18 at 06:49
  • https://stackoverflow.com/questions/43055902/qlpreviewcontroller-change-title/43057707#43057707 – Leo Dabus Feb 20 '18 at 06:51
  • Ya sure. Will try to use it and let u know if I find some difficulties – Catherine Feb 20 '18 at 06:52
  • Another option to share it is to use UIDocumentInteractionController https://stackoverflow.com/questions/46456481/how-to-write-a-file-to-a-folder-located-at-apples-files-app-in-swift-4/46457518#46457518 – Leo Dabus Feb 20 '18 at 06:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/165458/discussion-between-suganya-marlin-and-leo-dabus). – Catherine Feb 20 '18 at 06:55

1 Answers1

1

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