如何与UIActivityView Controller或UIDocumentInteractionController共享excel文件?

时间:2017-10-10 08:34:38

标签: ios swift uiactivityviewcontroller uidocumentinteraction

我想与UIAtivityViewController或UIDocumentInteractionController共享excel文件

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 我在UIDocumentInteractionController中使用此代码。我还在Info选项卡中添加了一些键。

当我共享excel文件时,会打开共享视图但文件不共享。请帮帮我。

0 个答案:

没有答案
相关问题