2016-10-26 3 views
1

내 응용 프로그램에 전자 메일 작성 기능이 있으며 Swift 2.2에서 완벽하게 작동했습니다. 최근에 코드를 Swift 3.0으로 마이그레이션하고이 문제로 고생했습니다. 아래에 내 코드를 공유 : 내가 자기에 mailComposeDelegate를 설정 한Swift 3.0 이전 후 MFMailComposeViewControllerDelegate 메서드가 호출되지 않음

import MessageUI 

class ViewController: UIViewController,  MFMailComposeViewControllerDelegate { 
func sendEmail() { 
    if MFMailComposeViewController.canSendMail() { 
     let mail = MFMailComposeViewController() 
     mail.mailComposeDelegate = self 
     mail.setToRecipients(["some[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() 
    } 
} 

, 위임 방법에 _ 넣고 검색에서 발견 된 모든 솔루션을 시도했다. 그러나 문제를 해결할 수 없습니다.

도움을 주시면 대단히 감사하겠습니다.

답변

7

그것은 8. 다음 해결 방법은 나를 위해 일한 엑스 코드에서 알려진 문제 :

@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 –

관련 문제