将用户图像附加到电子邮件

发布于 2025-01-30 20:55:12 字数 1385 浏览 3 评论 0原文

我正在尝试创建一个应用程序,用户可以在其中发送带有他们选择的图像附件的电子邮件,我已经使用Uitextfield进行了此操作。文本字段中的用户类型的内容也包含在电子邮件中。

我的代码如下:

@IBOutlet var fullName: UITextField!

@IBOutlet var latestPayslip: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
           let tap = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard))
    view.addGestureRecognizer(tap)
    // Do any additional setup after loading the view.
    fullName.addToolBar()
   
    fullName.delegate = self
    
}


@IBAction func sendEmail(_ sender: Any) {
    if MFMailComposeViewController.canSendMail() {
        let mail = MFMailComposeViewController()
        let emailFullName: String = fullName.text!
    
        mail.mailComposeDelegate = self
        mail.setToRecipients([“[email protected]"])
        mail.setMessageBody("<p>FullName: \(emailFullName)</p>", isHTML: true)
        mail.setSubject("Application for RTO: ")

        present(mail, animated: true)
        
    }
}
   
private lazy var primaryTextFields: [UITextField] = {
    [fullName]
}()

@objc func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}

}

I'm trying to create an app whereby the user can send an email with an image attachment of their choice, I've done this so far with UITextfield. What ever the user types in the Text Field it is also included in the email.

My code is as follows:

@IBOutlet var fullName: UITextField!

@IBOutlet var latestPayslip: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
           let tap = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard))
    view.addGestureRecognizer(tap)
    // Do any additional setup after loading the view.
    fullName.addToolBar()
   
    fullName.delegate = self
    
}


@IBAction func sendEmail(_ sender: Any) {
    if MFMailComposeViewController.canSendMail() {
        let mail = MFMailComposeViewController()
        let emailFullName: String = fullName.text!
    
        mail.mailComposeDelegate = self
        mail.setToRecipients([“[email protected]"])
        mail.setMessageBody("<p>FullName: \(emailFullName)</p>", isHTML: true)
        mail.setSubject("Application for RTO: ")

        present(mail, animated: true)
        
    }
}
   
private lazy var primaryTextFields: [UITextField] = {
    [fullName]
}()

@objc func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文