【发布时间】:2016-01-14 00:05:43
【问题描述】:
我尝试了几种方法来使用 UIAlertController,而不是 UIAlertView,但我无法发出警报。提前感谢您提供任何进一步的建议。我是新手。
UIAlertView' 在 iOS 9.0 中已弃用:UIAlertView 已弃用。将 UIAlertController 与 UIAlertControllerStyleAlert 的首选样式一起使用
这是我的代码:
import MessageUI
class SecondViewController: UIViewController,MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func sendmail(sender: UIButton) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["blabla@gmail.com"])
mailComposerVC.setSubject("App Feedback")
mailComposerVC.setMessageBody("Feature request or bug report?", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
【问题讨论】:
-
什么不起作用?我看到了您的
UIAlertView代码,但没有看到您对UIAlertController的尝试。周围有很多教程。 Here 就是一个例子。 -
更新您的问题,尝试使用
UIAlertController。解释你遇到了什么问题。并进行一些搜索。使用UIAlertController的例子数不胜数。
标签: ios uialertview ios9 deprecated