2016-11-28 75 views
1

我的应用程序上有一个UIButton,它在点击时显示UIAlertView。警报视图将包含一个打开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),但您传递的是枚举的名称而不是传递特定的值。

邮件作曲家没有解雇的问题也很简单。您从未设置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

好像在var .alert = UIAlertController(title:“Alert”,消息:“您的设备无法发送电子邮件”,preferredStyle:UIAlertControllerStyle)上出现“预期模式”错误 – Miles

1

VAR警报= UIAlertController(标题:“警报”,邮件:“您的设备无法发送电子邮件”,preferredStyle:.Alert)

相关问题