电子邮件已完成但发送电子邮件窗口未关闭? [复制]
Posted
技术标签:
【中文标题】电子邮件已完成但发送电子邮件窗口未关闭? [复制]【英文标题】:Email finished but the send email window does not close? [duplicate] 【发布时间】:2017-05-09 13:23:54 【问题描述】:我的问题是我对 emailwindow 进行了编程,它确实会发送电子邮件,但是当它们被发送或我想关闭窗口时,什么都没有发生。
这是我的代码:
import Foundation
import UIKit
import MessageUI
class ContactViewController: UIViewController, MFMailComposeViewControllerDelegate, UIAlertViewDelegate
override func viewDidLoad()
super.viewDidLoad()
let mail = MFMailComposeViewController()
@IBAction func email(_ sender: Any)
if !MFMailComposeViewController.canSendMail()
let warnung = UIAlertController(title: "Email konnte nicht gesendet werden", message: "Dein Gerät unterstützt leider keine Email-Funktion.", preferredStyle: .alert)
let action1 = UIAlertAction(title: "OK", style: .default, handler: nil)
warnung.addAction(action1)
self.present(warnung, animated: true, completion: nil)
return
else
mail.mailComposeDelegate = self
mail.setToRecipients(["team@example.com"])
mail.setSubject("Message to you")
mail.setMessageBody("Hello,\n", ishtml: false)
present(mail, animated: true, completion: nil)
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?)
mail.dismiss(animated: true, completion: nil)
print("Yes!")
这是邮件窗口的屏幕截图: Just click on this link!
【问题讨论】:
为什么委托方法在email(_sender:)
方法内部,在else
测试中?
因为我认为当它在 else 方法中时效果更好
请注意,您的方法 didFinishWithResult
已在您的 IBAction 电子邮件方法中声明。您需要将该方法移出该 IBAction 方法。它必须是您的视图控制器的实例方法
【参考方案1】:
@IBAction func email(_ sender: Any)
if !MFMailComposeViewController.canSendMail()
let warnung = UIAlertController(title: "Email konnte nicht gesendet werden", message: "Dein Gerät unterstützt leider keine Email-Funktion.", preferredStyle: .alert)
let action1 = UIAlertAction(title: "OK", style: .default, handler: nil)
warnung.addAction(action1)
self.present(warnung, animated: true, completion: nil)
return
else
mail.mailComposeDelegate = self
mail.setToRecipients(["team@example.com"])
mail.setSubject("Message to you")
mail.setMessageBody("Hello,\n", isHTML: false)
present(mail, animated: true, completion: nil)
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?)
mail.dismiss(animated: true, completion: nil)
print("Yes!")
【讨论】:
以上是关于电子邮件已完成但发送电子邮件窗口未关闭? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
Office 365上的“我的电子邮件”未收到电子邮件,但可以发送
Thunderbird:您的消息已发送,但副本未放在您发送的文件夹中
MFMailComposeViewController 视图不会第二次关闭