Swift 3,iOS10.3-电子邮件窗口打开,但不';关不上
我可以通过按下按钮在iOS 10.3中打开电子邮件窗口,但无法关闭它(取消和发送不关闭它)。由于我是Swift新手,我假设在我的代码中有一个明显的错误:)Swift 3,iOS10.3-电子邮件窗口打开,但不';关不上,ios,swift,email,window,Ios,Swift,Email,Window,我可以通过按下按钮在iOS 10.3中打开电子邮件窗口,但无法关闭它(取消和发送不关闭它)。由于我是Swift新手,我假设在我的代码中有一个明显的错误:) }您正在混合使用Swift 2和Swift 3方法。例如,func-mailComposeController(控制器:MFMailComposeViewController!,最终结果:mfmailcomposesult,错误:NSError!)需要替换为func-mailComposeController(\uController:MFM
}您正在混合使用Swift 2和Swift 3方法。例如,
func-mailComposeController(控制器:MFMailComposeViewController!,最终结果:mfmailcomposesult,错误:NSError!)
需要替换为func-mailComposeController(\uController:MFMailComposeViewController,最终结果:mfmailcomposesult,错误:error?)
请参见Swift类型NSError
vsError
,以及“u”和不太详细的参数说明:`didFinishWithResult:`vsdidFinishWithResult:
。因此不会调用您的方法,因为它不是预期的方法。的可能重复
import UIKit
import MessageUI
import Foundation
class settings: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func sendEmailButtonTapped(_ sender: Any) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["email@email.com"])
mailComposerVC.setSubject("Subject of email")
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send Email. Please check Email configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
controller.dismiss(animated: true, completion: nil)
}