2017-05-09 11 views
0

내 문제는 emailwindow를 프로그래밍하고 이메일을 보내지 만 보낼 때나 창문을 닫고 싶을 때 아무 일도 일어나지 않는다는 것입니다.이메일을 완료했지만 이메일 보내기 창이 닫히지 않습니까?

import Foundation 
import UIKit 
import MessageUI 


class ContactViewController: UIViewController, MFMailComposeViewControllerDelegate, UIAlertViewDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

let mail = MFMailComposeViewController() 


    @IBAction func email(_ sender: Any) { 

     if !MFMailComposeViewController.canSendMail() { 
      let warnung = UIAlertController(title: "Email konnte nicht gesendet werden", message: "Dein Gerät unterstützt leider keine Email-Funktion.", preferredStyle: .alert) 
      let action1 = UIAlertAction(title: "OK", style: .default, handler: nil) 
      warnung.addAction(action1) 
      self.present(warnung, animated: true, completion: nil) 
      return 

      } else { 

       mail.mailComposeDelegate = self 
       mail.setToRecipients(["[email protected]"]) 
       mail.setSubject("Message to you") 
       mail.setMessageBody("Hello,\n", isHTML: false) 

       present(mail, animated: true, completion: nil) 

      func mailComposeController(_ controller: MFMailComposeViewController, 
             didFinishWithResult result: MFMailComposeResult, error: NSError?) { 
       mail.dismiss(animated: true, completion: nil) 
       print("Yes!") 
       } 


      } 
     } 
} 
메일 창

Here'sa 스크린 샷 : Just click on this link!

+0

가 왜'이메일 내부의 위임 방법 (_sender :)를'방법, 그건 내 코드 그게 전부

'else' 테스트? – Larme

+0

else 메서드 내부에있을 때 더 잘 작동한다고 생각했기 때문에 – me21

+0

'didFinishWithResult'라는 메서드가 IBAction 전자 메일 메서드에서 선언되었습니다. IBAction 메서드에서 해당 메서드를 이동해야합니다. 보기 컨트롤러의 인스턴스 메서드 여야합니다. –

답변

0
@IBAction func email(_ sender: Any) { 

    if !MFMailComposeViewController.canSendMail() { 
     let warnung = UIAlertController(title: "Email konnte nicht gesendet werden", message: "Dein Gerät unterstützt leider keine Email-Funktion.", preferredStyle: .alert) 
     let action1 = UIAlertAction(title: "OK", style: .default, handler: nil) 
     warnung.addAction(action1) 
     self.present(warnung, animated: true, completion: nil) 
     return 

     } else { 

      mail.mailComposeDelegate = self 
      mail.setToRecipients(["[email protected]"]) 
      mail.setSubject("Message to you") 
      mail.setMessageBody("Hello,\n", isHTML: false) 

      present(mail, animated: true, completion: nil) 
     } 
    } 
} 

func mailComposeController(_ controller: MFMailComposeViewController, 
            didFinishWithResult result: MFMailComposeResult, error: NSError?) { 
      mail.dismiss(animated: true, completion: nil) 
      print("Yes!") 
}