我的应用程序上有一个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)
}
请你的问题缩小到一个问题,只是相关的代码。你有两个完全不同的问题和太多不相关的代码。 – rmaddy
@rmaddy当然,我已经编辑过这篇文章。 – Miles