我的项目的目的是拥有一个登录/创建帐户屏幕,用户点击一个按钮,用他们的用户名和电子邮件向他们发送电子邮件。密码验证它。
注意:用户名,密码和电子邮件是在我的项目的不同类中声明的全局变量 编辑:有人说要在文件的末尾添加一些东西?那有什么意思?有人可以帮忙吗?
错误的屏幕截图: enter image description here
SendEmailToVerifyPassword类:
import UIKit
import MessageUI
class SendEmailToVerifyPassword: MFMailComposeViewController
{
func ViewDidLoad()
{
super.viewDidLoad()
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients([email])
mailComposerVC.setSubject("Your password/username verification")
mailComposerVC.setMessageBody("Hello.\n Your username is: \(username)\n Your password is \(password)", 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()
}
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
switch result.rawValue {
case MFMailComposeResultCancelled.rawValue:
print("Cancelled mail")
case MFMailComposeResultSent.rawValue:
print("Mail Sent")
default:
break
}
self.dismissViewControllerAnimated(true, completion: nil)
}
}
故事板按钮viewcontroller的屏幕截图(点击这里是我要激活电子邮件的按钮): enter image description here
答案 0 :(得分:1)
class SendEmailToVerifyPassword: MFMailComposeViewController, MFMailComposeViewControllerDelegate
{
...
}