gpt4 book ai didi

email - 向消息正文添加额外的字符串(swift)

转载 作者:行者123 更新时间:2023-11-28 07:11:28 25 4
gpt4 key购买 nike

我的电子邮件工作正常。我唯一需要做的就是在我的邮件正文中添加一个额外的字符串。例如,我想将 Name: 和文本字段添加到我的邮件正文中。像这样的东西。

姓名:约翰·史密斯

电话:566-654-6577

邮箱:Smith@smith.com

目前,消息正文仅显示以下内容。

约翰·史密斯

566-654-6577

Smith@smith.com

import UIKit
import MessageUI


class EmailTableViewController: UITableViewController, MFMailComposeViewControllerDelegate, UITextFieldDelegate {


@IBOutlet weak var name: UITextField!

@IBOutlet weak var phone: UITextField!

@IBOutlet weak var email: UITextField!


func appendTextFromTextField(string: String, textField: UITextField) -> String {
return string + textField.text + "\n \n"
}


@IBAction func SendEmailButton(sender: AnyObject) {


var fields: [UITextField] = [name, phone, email]
var messageBody = ""

for f in fields {
messageBody = appendTextFromTextField(messageBody, textField: f)
}

var emailTitle = "Interface Information"
var toRecipents = [""]
var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toRecipents)
self.presentViewController(mc, animated: true, completion: nil)

}

func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
switch result.value {
case MFMailComposeResultCancelled.value:
println("Mail cancelled")
case MFMailComposeResultSaved.value:
println("Mail saved")
case MFMailComposeResultSent.value:
println("Mail sent")
case MFMailComposeResultFailed.value:
println("Mail sent failure: %@", [error.localizedDescription])
default:
break
}
self.dismissViewControllerAnimated(true, completion: nil)

}

override func viewDidLoad() {



super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}




}

最佳答案

删除 for 循环并尝试用这个方法替换您的方法:

@IBAction func sendEmailButton(sender: UIButton) {
var messageBody = "Name:\(name.text)\nPhone:\(phone.text)\nEmail:\(email.text) "
var emailTitle = "Interface Information"
var toRecipents = [""]
var mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toRecipents)
self.presentViewController(mc, animated: true, completion: nil)
}

关于email - 向消息正文添加额外的字符串(swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28282442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com