0

I am unable to share the msword and msexcel and ppt files in Swift Using UIActivityViewController

Here is the code snippet I am using

func ShareFileFromApptoIpad(filename : String!){
    let fileManager = FileManager.default
    let documentoPath = (self.getDirectoryPath() as NSString).appendingPathComponent("\(filename!)")

    print("doc\(documentoPath)")

    if fileManager.fileExists(atPath: documentoPath){
        let documento = NSData(contentsOfFile: documentoPath)
        let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: [documento!], applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView=self.view
        present(activityViewController, animated: true, completion: nil)
    }
    else {
        print("document was not found")
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

2

you can change your url Like this

let url = NSURL.fileURL(withPath: myFileName)

and then use in

let activityViewController = UIActivityViewController(activityItems: [url] , applicationActivities: nil)
tabassum
  • 1,100
  • 6
  • 17