0

약간의 코드에 오류가 있습니다. 나는 이것에 초보이고 나는 나 자신을 가르치려고 노력하고있다. 온라인 답변 대부분을 찾았지만이 특정 문제에 관해서는 아무것도 찾을 수 없습니다. 앱 내에서 이메일을 보내고 싶지만 언제든지 이메일 버튼을 누르면 MFMailViewController가 표시되지 않습니다. 내 UIButton이 작동하지 않는 것과 같습니다. 그러나 나는 그것이 IBAction이라는 것을 알고 있습니다. 지금까지 제 코드가 있습니다. 어떤 도움이라도 대단히 감사합니다. 장치 가 이메일을 보낼 수 없습니다 경우UIButton이 MFMailViewController를 불러 오지 않습니다.

import UIKit 
import MessageUI 

class RequestService: UIViewController,MFMailComposeViewControllerDelegate { 
    @IBOutlet weak var CustomerName: UITextField! 
    @IBOutlet weak var emailButton: UIButton! 

    @IBAction func sendEmail(_ sender: UIButton) { 
     if !MFMailComposeViewController.canSendMail() { 
      print("Mail services are not available") 

      let ComposeVC = MFMailComposeViewController() 
      ComposeVC.mailComposeDelegate = self 

      ComposeVC.setToRecipients(["[email protected]"]) 
      ComposeVC.setSubject("New Support Ticket") 
      ComposeVC.setMessageBody(CustomerName.text!, isHTML: false) 

      self.present(ComposeVC, animated: true, completion: nil) 
     } 

     func mailComposeController(controller: MFMailComposeViewController,didFinishWithResult result:MFMailComposeResult, error: NSError?) { 
      // Check the result or perform other tasks. 
      // Dismiss the mail compose view controller. 
      controller.dismiss(animated: true, completion: nil) 
     } 
    } 
} 
+0

시뮬레이터에서 테스트 하시겠습니까? 이것은 실제 iPhone 장치에서만 작동합니다. –

답변

0

sendMail 함수의 구문에서 오류가 발생했습니다. 장치 메일을 보낼 수없는 경우 게시 한 코드는보기 컨트롤러 만 열립니다. 이것을 다음과 같이 변경하십시오 :

@IBAction func sendEmail(_ sender: UIButton) { 
    if !MFMailComposeViewController.canSendMail() { 
     print("Mail services are not available") 
     return 
    } 

    let composeVC = MFMailComposeViewController() 
    composeVC.mailComposeDelegate = self 
    composeVC.setToRecipients(["[email protected]"]) 
    composeVC.setSubject("New Support Ticket") 
    composeVC.setMessageBody(CustomerName.text!, isHTML: false) 

    self.present(composeVC, animated: true, completion: nil) 
} 
+0

이메일을 보낼 수 없는데도 왜 메일 작성자에게 선물을 계속 하시겠습니까? – rmaddy

+0

@rmaddy 고침, 고마워. –

+0

너희들은 너의 물건을 안다! 방금 당신이 말한 것을 바꿨고 완벽하게 작동합니다! –

0

만 메일 컨트롤러를 표시하기 위해 시도합니다. 그것은 거꾸로입니다.

@IBAction func sendEmail(_ sender: UIButton) { 
    if MFMailComposeViewController.canSendMail() { 
     print("Mail services are not available") 

     let ComposeVC = MFMailComposeViewController() 
     ComposeVC.mailComposeDelegate = self 

     ComposeVC.setToRecipients(["[email protected]"]) 
     ComposeVC.setSubject("New Support Ticket") 
     ComposeVC.setMessageBody(CustomerName.text!, isHTML: false) 

     self.present(ComposeVC, animated: true, completion: nil) 
    } 
} 

func mailComposeController(controller: MFMailComposeViewController,didFinishWithResult result:MFMailComposeResult, error: NSError?) { 
    // Check the result or perform other tasks. 
    // Dismiss the mail compose view controller. 
    controller.dismiss(animated: true, completion: nil) 
} 

그리고 다른 방법 외에는 위임 메서드가 필요합니다.