如何通过iOS应用直接将表单发送到电子邮件地址?

时间:2019-07-04 10:21:07

标签: swift4 swift5

我想直接将iOS应用中的电子邮件发送到电子邮件地址。

我正在尝试集成此软件包,但是该软件包无法安装。 https://github.com/onevcat/Hedwig

我需要通过电子邮件发送表格。

2 个答案:

答案 0 :(得分:0)

1)在课程委托中添加MFMailComposeViewControllerDelegate

在函数中添加以下代码

  let composeVC = MFMailComposeViewController()
    composeVC.mailComposeDelegate = self
    // Configure the fields of the interface.
    composeVC.setToRecipients([email ?? ""])
    composeVC.setPreferredSendingEmailAddress(someEmail ?? "")
//        composeVC.setSubject("Message Subject")
    composeVC.setMessageBody("Checking", isHTML: false)
    // Present the view controller modally.
    self.present(composeVC, animated: true, completion: nil)

然后添加此功能以在关闭电子邮件视图时返回到应用程序

    func mailComposeController(_ controller: MFMailComposeViewController,
                           didFinishWith result: MFMailComposeResult, error: Error?) {
    // Check the result or perform other tasks.

    // Dismiss the mail compose view controller.
    controller.dismiss(animated: true, completion: nil)
}

答案 1 :(得分:0)

如果要从应用程序发送电子邮件,则需要显示一个视图(如MailComposer)。苹果不会让您在后台发送电子邮件。用户需要知道您正在发送电子邮件。 Hedwig 似乎可以运行,但是用于服务器端。

在Hedwig网站上引用注释:

  

我可以在iOS中使用它吗?目前,Swift Package Manager不支持   适用于iOS,watchOS或tvOS平台。所以答案是否定的。但是这个   框架不仅仅在iOS中使用任何东西(例如UIKit),所以尽快   由于Swift Package Manager支持iOS,因此您也可以在其中使用它。

相关问题