Ios MFMailComposeViewController未解除-Swift,Xcode
我目前正在尝试实现Ios MFMailComposeViewController未解除-Swift,Xcode,ios,swift,xcode,mfmailcomposeviewcontroller,Ios,Swift,Xcode,Mfmailcomposeviewcontroller,我目前正在尝试实现MFMailComposeViewController。一切正常,除了发送电子邮件或单击“取消”后,MFMailComposeViewController不会关闭。我看过类似的StackOverflow线程,并试图实现这些解决方案,但它们并没有解决我的问题。我觉得问题可能不在func-mailComposeController中,而是在我的代码的其余部分中。任何帮助都将不胜感激 我的代码: if MFMailComposeViewController.canSendMai
MFMailComposeViewController
。一切正常,除了发送电子邮件或单击“取消”后,MFMailComposeViewController
不会关闭。我看过类似的StackOverflow线程,并试图实现这些解决方案,但它们并没有解决我的问题。我觉得问题可能不在func-mailComposeController
中,而是在我的代码的其余部分中。任何帮助都将不胜感激
我的代码:
if MFMailComposeViewController.canSendMail() {
let vc = MFMailComposeViewController()
vc.delegate = self
vc.mailComposeDelegate = self
vc.setSubject("Contact Us/Feedback")
vc.setToRecipients(["test@gmail.com"])
present(vc, animated: true)
}
else {
if let url = URL(string: "https://www.google.com") {
let safariVC = SFSafariViewController(url: url)
present(safariVC, animated: true, completion: nil)
}
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
}
谢谢 变化
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
到
改变
到
另外,请删除
vc.delegate=self
,因为它什么也不做。嗨,Matt,我已经实现了这个编辑,但是,它并不能解决我的问题。MFMailComposeViewController仍然不会关闭。我还删除了vc.delegate=self-ThanksOh,并将整个方法(包括两个大括号)剪切并粘贴到类声明的顶层。您已经在另一个方法中编写了它,在这个方法中它永远不能被调用。另外,删除vc.delegate=self
,因为它什么也不做。嗨,Matt,我已经实现了这个编辑,但是,它并不能解决我的问题。MFMailComposeViewController仍然不会关闭。我还删除了vc.delegate=self-ThanksOh,并将整个方法(包括两个大括号)剪切并粘贴到类声明的顶层。您已经在另一个方法中编写了它,在这个方法中永远无法调用它。
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult, error: Error?) {