func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
すると、このデリゲート
MFMailComposeViewControllerDelegate
に加入するようにしてくださいスウィフト3では、あなたはこの
@IBAction func emailLogs(_ sender: Any) {
let allPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = allPaths.first!
let pathForLog = documentsDirectory.appending("/application.log")
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self;
mail.setToRecipients(["[email protected]"])
mail.setSubject("Application Logs")
mail.setMessageBody("Please see attached", isHTML: true)
if let fileData = NSData(contentsOfFile: pathForLog) {
mail.addAttachmentData(fileData as Data, mimeType: "text/txt", fileName: "application.log")
}
self.present(mail, animated: true, completion: nil)
}
}
のような添付ファイル付きのメールを送信することができます。そして結果に作曲コントローラを却下します
ありがとう、同僚! – Alex
@Alexey私の喜び:-) –