0
私の問題は、emailwindowをプログラムして電子メールを送信することですが、送信した場合や、ウィンドウを閉じたい場合は何も起こりません。私のコードザッツメールは終了しましたが、メールの送信ウィンドウは閉じませんか?
:メールウィンドウの
import Foundation
import UIKit
import MessageUI
class ContactViewController: UIViewController, MFMailComposeViewControllerDelegate, UIAlertViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
let mail = MFMailComposeViewController()
@IBAction func email(_ sender: Any) {
if !MFMailComposeViewController.canSendMail() {
let warnung = UIAlertController(title: "Email konnte nicht gesendet werden", message: "Dein Gerät unterstützt leider keine Email-Funktion.", preferredStyle: .alert)
let action1 = UIAlertAction(title: "OK", style: .default, handler: nil)
warnung.addAction(action1)
self.present(warnung, animated: true, completion: nil)
return
} else {
mail.mailComposeDelegate = self
mail.setToRecipients(["[email protected]"])
mail.setSubject("Message to you")
mail.setMessageBody("Hello,\n", isHTML: false)
present(mail, animated: true, completion: nil)
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
mail.dismiss(animated: true, completion: nil)
print("Yes!")
}
}
}
}
Here'saスクリーンショット:それでだ、 `メソッド: Just click on this link!
なぜデリゲートメソッドは'電子メール(_sender)の内部にあります'else'テスト? – Larme
elseメソッドの中にあるとうまくいくと思ったから – me21
あなたのメソッドdidFinishWithResultがあなたのIBAction電子メールメソッドの中で宣言されていることに注意してください。そのメソッドをそのIBActionメソッドから移動する必要があります。あなたのView Controllerのインスタンスメソッドである必要があります –