2016-09-26 79 views
1

我有一個簡單的iOS10應用程序正在構建。我建立了一個頁面,用戶可以添加主題行和電子郵件的正文。當點擊發送電子郵件按鈕時,MFMailViewCompose正常啓動,如果我點擊發送電子郵件發送。但是,MFMailViewCompose不會在發送或取消時關閉。MFMailViewCompose不會關閉

下面是代碼

import UIKit 
import MessageUI 

class EnglishEmailHelpdeskVC: UIViewController, MFMailComposeViewControllerDelegate { 

override func viewDidLoad() { 
super.viewDidLoad() 
// Do any additional setup after loading the view. 
} 

override func didReceiveMemoryWarning() { 
super.didReceiveMemoryWarning() 
// Dispose of any resources that can be recreated. 
} 

//Helpdesk Email Subject Line and Body. 
@IBOutlet var EmailHelpdeskSubjectLine: UITextField! 
@IBOutlet var EmailHelpdeskBody: UITextView! 

var MailControllerCompose:MFMailComposeViewController! 

//Helpdesk Send Email Button. 
@IBAction func EmailHelpdeskSendButton(_ sender: AnyObject) { 
let HDSubjectLine = EmailHelpdeskSubjectLine.text 
let HDBody = EmailHelpdeskBody.text 

MailControllerCompose = MFMailComposeViewController() 
MailControllerCompose.mailComposeDelegate = self 
MailControllerCompose.setToRecipients(["[email protected]"]) 
MailControllerCompose.setSubject(HDSubjectLine!) 
MailControllerCompose.setMessageBody(HDBody!, isHTML: false) 

self.present(MailControllerCompose, animated: true, completion: nil) 

} 

@nonobjc func MFMailComposeViewContoller(controller: MFMailComposeViewController,didFinishWithResult result:MFMailComposeResult, error: NSError?){ 
MailControllerCompose.dismiss(animated: true, completion: nil) 
} 
} 

請幫幫忙!

回答

0

頗有幾分這個問題的戰鬥後,這裏是最終爲我工作:

public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Swift.Error?) { 
    controller.dismiss(animated: true, completion: nil) 
} 

的關鍵部分是在最後一個參數Swift.Error。如果沒有Swift限定符,Error解析爲UIViewController.Error,這與我們嘗試覆蓋的方法不匹配。我懷疑你的選擇NSError出於同樣的原因失敗。

(值得注意的是,我的不正確Error類型顯然是從PromiseKit未來,而不是作爲的UIKit我本來以爲)

+0

其他人似乎來到了同樣的結論:http://stackoverflow.com/a/ 58603分之39623586 –