首先,在視圖控制器類的頂部,其中共享是採取地方,我們把一個聲明爲UIDocumentInteractionController:
//在你的類的頂部你把
var controller = UIDocumentInteractionController()
//然後一個IBAction爲連接起來,分享按鈕,在你的底欄是這樣的:
@IBAction func SHARE(_ sender: Any) {
let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)[0] as String
// Here we've used user defaults to store the name of an audio recording, but you could use a variable
let recordingName = UserDefaults.standard.value(forKey: "recordingName") as! String
let pathArray = [dirPath, recordingName] as [String]
let filePathString: String = pathArray.joined(separator: "/") as String
var path = Bundle.main.path(forResource: filePathString as! String?, ofType: "wav")
controller = UIDocumentInteractionController(url: NSURL(fileURLWithPath: filePathString as! String) as URL)
let button = sender as! Any
let view = self.view
controller.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
}