2016-10-26 9 views
1

私のアプリケーションにはメール作成機能があり、Swift 2.2で完全に機能していました。最近、私はコードをSwift 3.0に移行し、この問題を解決しました。以下の私のコードスニペットの共有:Swift 3.0の移行後にMFMailComposeViewControllerDelegateメソッドが呼び出されない

import MessageUI 

class ViewController: UIViewController,  MFMailComposeViewControllerDelegate { 
func sendEmail() { 
    if MFMailComposeViewController.canSendMail() { 
     let mail = MFMailComposeViewController() 
     mail.mailComposeDelegate = self 
     mail.setToRecipients(["[email protected]"]) 
     mail.setSubject("Sending you an in-app e-mail...") 
     mail.setMessageBody("<p>You're so awesome!</p>", isHTML: true) 
     self.present(mail, animated: true) 
    } else { 
     // handle failure 
    } 
    } 

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { 

    controller.dismiss(animated: true) 
    } 

@IBAction func mailClicked(_ sender: AnyObject) {  
    sendEmail() 
    } 
} 

を私は、デリゲートメソッドで_を入れて、自己にmailComposeDelegateを設定し、検索で見つかったすべてのソリューションを試してみました。しかし、問題を解決できませんでした。

ご協力いただきまして誠にありがとうございます。

答えて

7

ことである8.次の回避策は、私のために働いたXcodeで既知の問題:

@objc(mailComposeController:didFinishWithResult:error:) 
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: NSError?) { 
controller.dismiss(animated: true, completion: nil) 
} 
+0

類似し、全てスウィフト、解決策:http://stackoverflow.com/a/39623586/1473527 –

関連する問題