我希望视图控制器只包含文本字段和发送按钮。有没有办法让按钮将文本字段的内容发送到预设的电子邮件地址?或者是唯一的电子邮件功能MFMailComposeViewController
?
答案 0 :(得分:1)
您只能通过 MFMailComposeViewController
发送邮件,但您可以从文本字段中传递值,如下例所示。
将此代码放在按钮操作中:
let toRecipients = ["mail@mail.com"]
let subject = "My Subject"
let body = textField.text // Your text fields text
mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(toRecipients)
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: false)
presentViewController(mail, animated: true, completion: nil)