我在构建一个应用程序,该应用程序构造一个电子邮件并将其呈现在MFMailComposeViewController中供用户发送。当用户发送或取消它时,我希望应用程序用适当的确认屏幕消息进行响应。Swift 3如何显示基于MFMailComposeResult电子邮件屏幕的确认屏幕
我可以编写电子邮件,解除撰写屏幕,并且我在IB中有一个从预编写视图到确认视图的已命名的segue。但我无法让这个继续执行。
所以,我怎么能在SEGUE目的地更新的文字信息,然后Segue公司给它。
因为我试图学习Swift,我对理解代码如何工作非常感兴趣,而不仅仅是获取可用的代码。所以我真的很感激任何帮助。
工作流程开始于用户抢购从应用程序中的照片:
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
,所有的电子邮件内容的汇编,并将其传递到:
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
然后将此火灾时用户点击“发送”“取消”
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/mfmailcomposeviewcontroller/1616890-mailcomposedelegate) –