2016-11-28 3 views
1

탭했을 때 UIAlertView를 표시하는 앱에 UIButton이 있습니다. 알림보기에는 iOS 이메일 작성보기를 여는 버튼이 있습니다.'UIAlertControllerStyle.Type'유형의 값을 예상되는 인수 유형 'UIAlertControllerStyle'로 변환 할 수 없습니다.

메일 작성보기가 훌륭하게 작동하지만 사용자가 이메일을 보내거나 "취소"를 누르면 메일 작성보기가 사라지지 않습니다. 나는이 오류가 이대로가 보이지 않는다 사용하고 코드는 작동합니다 :

유형의 값 예상 인수 유형 'UIAlertControllerStyle.Type을'변환 할 수 없습니다 'UIAlertControllerStyle'

  var alert = UIAlertController(title: "Alert", message: "Your Device cannot send emails", preferredStyle: UIAlertControllerStyle) 

수 있습니다 무엇 여기서? 감사!

var myMail: MFMailComposeViewController! 

@IBAction func helpfeedbackAlert(_ sender: Any) { 

    if(MFMailComposeViewController.canSendMail()){ 
     myMail = MFMailComposeViewController() 

     myMail.setSubject("Test") 
     myMail.setToRecipients(["[email protected]"]) 

     self.present(myMail, animated: true, completion: nil) 
    } 
    else{ 
     var alert = UIAlertController(title: "Alert", message: "Your Device cannot send emails", preferredStyle: UIAlertControllerStyle) 
     self.present(alert, animated: true, completion: nil) 

    } 

} 

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view.   
} 

func mailComposeController(controller: MFMailComposeViewController!, didFinishWith: MFMailComposeResult, error: NSError!){ 

    switch result.rawValue { 

    case MFMailComposeResult.cancelled.rawValue: 
     print("Mail cancelled") 

    case MFMailComposeResult.sent.rawValue: 
     print("Your email has been sent!") 

    case MFMailComposeResult.failed.rawValue: 
     print("Email has failed to send: %@", [error!.localizedDescription]) 
    default: 
     break 

    } 

    // Dismiss the mail compose view controller 
    controller.dismiss(animated: true, completion: nil) 


} 
+0

하나의 문제가 단지 관련 코드에 질문을 좁힐하십시오. 완전히 다른 두 가지 문제와 관련성이없는 코드가 너무 많습니다. – rmaddy

+0

@rmaddy 물론, 게시물을 편집했습니다. – Miles

답변

2

경고 문제는 간단합니다. 특정 경고 스타일 (.alert)을 지정해야하지만 특정 값을 전달하는 대신 enum의 이름을 전달하고 있습니다.

메일 작성자가 해고하지 않는 문제는 간단합니다. mailComposeDelegate 속성을 설정하지 않았습니다.

switch의 문제점은 잘못된 메서드 서명이 있다는 것입니다. 다음과 같아야합니다 :

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

그리고 rawValue을 모두 사용할 필요는 없습니다.

+0

스위치 수정이 훌륭하게 작동합니다. 감사합니다! 어떻게 경고 스타일을 지정하고 mailComposeDelegate 속성을 설정합니까? 나는 이미 이것을 다음과 같이 생각했다. if (MFMailComposeViewController.canSendMail()) { myMail = MFMailComposeViewController() – Miles

+0

경고 스타일에 사용할 값을 이미 보여 줬다. 메일 위임자에게는'myMail.mailComposeDelegate = self'가 필요합니다. – rmaddy

+0

다시 "UIAlertControllerStyle"을 다음과 같이 바꿔야합니다 : var .alert = UIAlertController (제목 : "경고", 메시지 : "귀하의 장치는 이메일을 보낼 수 없습니다", preferredStyle : UIAlertControllerStyle) – Miles

1

var에 경고 = UIAlertController (제목 : "경고", 메시지 : "장치가 이메일을 보낼 수 없습니다", preferredStyle : .Alert)

관련 문제