電子メールを作成し、ユーザーが送信するためにMFMailComposeViewControllerに表示するアプリケーションを構築しています。ユーザーがそれを送信またはキャンセルすると、アプリは適切な確認画面メッセージで応答します。Swift 3 MFMailComposeResult電子メール画面に基づいて確認画面を表示する方法
私は電子メールを作成し、作成画面を閉じることができました。私は、IBの名前のついたセグをプリコンポーズビューから確認ビューまで持っています。しかし、私はそのセグを実行することはできません。
したがって、どのようにしてセグの宛先のテキストメッセージを更新し、それにセグをすることができますか。
私はSwiftを学ぼうとしているので、コードの仕組みを理解することに非常に関心があります。だから私は本当に助けに感謝します。
ワークフローでは、アプリから写真を撮って、ユーザから始まる:この火災
func presentMailComposer(mail : MFMailComposeViewController) {
if MFMailComposeViewController.canSendMail() {
self.present(mail, animated: true, completion: nil)
} else {
let sendMailErrorAlert = UIAlertController.init(title: "Uh oh!", message: "Unable to send email.", preferredStyle: .alert)
self.present(sendMailErrorAlert, animated: true, completion: nil)
} // close if
} // close presentEmailComposer
のとき:電子メールメッセージの内容のすべてを組み立て、それを渡す
func snapPhoto(){
if let cameraConnection = sessionOutput.connection(withMediaType: AVMediaTypeVideo) {
sessionOutput.captureStillImageAsynchronously(from: cameraConnection, completionHandler: { buffer, error in
let myMessage = self.buildEmail()
let myJpg = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer)
let mapSnap = (self.myMap == nil) ? nil : UIImagePNGRepresentation(self.myMap!)
let mail = self.setupMail(to: myMessage.to, subject: myMessage.subject, body: myMessage.body, myJpg: myJpg!, mapSnap: mapSnap)
self.presentMailComposer(mail: mail)
}) // close completionHandler
} // close if let cameraConnection
} // close func snapPhoto
ユーザーは「キャンセル」の「送信」をタップします
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
switch result.rawValue {
case MFMailComposeResult.cancelled.rawValue:
self.performSegue(withIdentifier: "afterEmail", sender: self)
print("Mail cancelled")
case MFMailComposeResult.saved.rawValue:
print("Mail saved")
case MFMailComposeResult.sent.rawValue:
print("Mail sent")
case MFMailComposeResult.failed.rawValue:
print("Mail sent failure: %@", [error!.localizedDescription])
default:
break
}
controller.dismiss(animated: true, completion: nil)
} // close mailCompose
これは自分自身が困惑している場所です。私はMFMailComposeResultにアクセスすることができますが、それは正しいですが、確認ビューを表示する方法を理解することができないので、作成ビューがスライドすると利用可能になります。
あなたが試したことを理解するためのコードを追加する必要があります。私は['mailComposeDelegate'](https://developer.apple.com/reference/messageui/mfmailcomponentsviewcontroller/1616890-mailcomposedelegate)をチェックしてください。 –