我的應用程序上有一個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