0

I want to share excel file with UIAtivityViewController or UIDocumentInteractionController

let documentsPath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(self.stateMentType)

                do {

                    _ = try data?.write(to: URL.init(fileURLWithPath: documentsPath), options: .atomicWrite)

                }

                catch {
                    print("Error in writing \(error)")
                }

                let documents = NSData(contentsOfFile: documentsPath)


                if fileManager.fileExists(atPath: documentsPath) {
                      //  let activityController = UIActivityViewController(activityItems: [documents!], applicationActivities: nil)
                     //   self.present(activityController, animated: true, completion: nil)

                    let url = URL(fileURLWithPath: documentsPath)
                    let dc = UIDocumentInteractionController(url: url)
                    dc.uti = "public.data"
                        dc.presentOpenInMenu(from: self.view.bounds, in: self.view, animated: true)
                    // dc.presentOptionsMenu(from: self.view.bounds, in: self.view, animated: true)
                }

enter image description here I am using this code with UIDocumentInteractionController. I am also added some key in Info Tab.

When i share the excel file , sharing views is opened but file is not sharing. Please help me .

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Tinku
  • 247
  • 1
  • 3
  • 13
  • You can use this answer to share any file type. The trick is to use URL method getResiurcesValue to get its UTI https://stackoverflow.com/a/46457518/2303865 – Leo Dabus Oct 10 '17 at 10:40
  • You can use `public.data, public.content` as a general uti also for the document types – Leo Dabus Oct 10 '17 at 10:44
  • Btw if it solves your problem let me know so I can close it as duplicate because I am not supposed to answer the same thing twice – Leo Dabus Oct 10 '17 at 10:49

0 Answers0