1

I need to share a file (it can be pdf, xlsx or an image) using a Sharesheet. It works on whatsapp or other apps but when I select "mail" only opens mail app but without any attachment. Here is my code:

let myURL = URL(fileURLWithPath: fileURLString)
let activityItems: [AnyObject] = [myURL as AnyObject]
let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView=self.view
self.present(activityViewController, animated: true, completion: nil)

(I am running it in the main thread from an asynchronous task)

Vittoria
  • 11
  • 1
  • You can use `MFMailComposeViewController ` instead of `UIActivityViewController`, please check this out -> https://stackoverflow.com/a/38376049/7512091 – emrcftci Mar 03 '20 at 12:11
  • You are missing this line, you must provide it into work on iPad. activityViewController.popoverPresentationController?.sourceRect=... Also, could you print the description of myURL and share it here? – Iliyan Kafedzhiev Mar 13 '20 at 23:18
  • You can add the file as NSData, that works for standard iOS Mail app, but it doesn't for another apps. – Ivan Androsenko Feb 18 '21 at 09:20

0 Answers0