我在構建一個應用程序,該應用程序構造一個電子郵件並將其呈現在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) –