まず、共有は我々が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)
}