我的答案是使用 UIDocumentInteractionController 来执行此操作。
我首先在班级顶部实例化一个 UIDocumentInteractionController
var controller = UIDocumentInteractionController()
然后我将 IBAction 链接到我的 nib 或 Storyboard 上的共享按钮:
@IBAction func SHARE(_ sender: Any) {
let dirPath: String = NSSearchPathForDirectoriesInDomains(.documentDirectory,
.userDomainMask,
true)[0]
let recordingName = UserDefaults.standard.string(forKey: "recordingName")
let pathArray: [String] = [dirPath, recordingName!]
let filePathString: String = pathArray.joined(separator: "/")
controller = UIDocumentInteractionController(url: NSURL(fileURLWithPath: filePathString) as URL)
controller.presentOpenInMenu(from: CGRect.zero,
in: self.view,
animated: true)
}