我在使用MFMailComposer时遇到了麻烦。我已经使用示例Swift Code跟踪了iOS开发人员指南。
我还在本网站上查看了以下类似的问题:
swift - dismissing mail view controller from Sprite Kit
MFMailComposeViewController in Swift does not dismiss
Linked Frameworks&库:MessagesUI.framework
import MessageUI
class FHCLLeftMenuViewController: FHBaseViewController,UITableViewDelegate,UITableViewDataSource,MFMailComposeViewControllerDelegate
当我点击我的应用程序左侧幻灯片菜单中的支持文本时,会出现Mail应用程序,我撰写电子邮件并单击发送。电子邮件显示在我的收件箱中,但控制器在发送邮件后并未自行解除。当我尝试删除草稿时,也会发生这种情况,我必须关闭应用程序并重新启动它。
case kFHCLMenuTagSupport:
//PT DashBoard
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["support@example.com"])
composeVC.setSubject("Client Support")
composeVC.setMessageBody("Some text here.", isHTML: false)
// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
self.dismissViewControllerAnimated(true, completion: nil)
}
break
我也尝试过这种变体,以相同的结果返回应用的主信息中心:
case kFHCLMenuTagSupport:
//PT DashBoard
let storyboard = UIStoryboard(name: "Client", bundle: nil)
// Create View Controllers
let mainPage:FHClientDashBoardViewController = storyboard.instantiateViewControllerWithIdentifier("FHClientDashBoardViewController") as! FHClientDashBoardViewController
let mainPageNav = UINavigationController(rootViewController: mainPage)
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["support@example.com"])
composeVC.setSubject("Client Support")
composeVC.setMessageBody("Some text here.", isHTML: false)
// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
// self.dismissViewControllerAnimated(true, completion: nil)
self.mm_drawerController.setCenterViewController(mainPageNav, withCloseAnimation: true, completion: nil)
}
break
任何帮助将不胜感激。
答案 0 :(得分:0)
dismissViewControllerAnimated(_:completion:)
函数解除调用该函数的视图控制器。在这种情况下,由于您在self
上调用它,它会尝试解除FHCLLeftMenuViewController
。这可以通过dismissViewControllerAnimated(_:completion:)
上的MFMailComposeViewController
来轻松解决。
要执行此操作,只需使用以下内容替换您的mailComposeController(controller:didFinishWithResult:error:)
功能(在Apple自己的文档中也会以这种方式显示):
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
controller.dismissViewControllerAnimated(true, completion: nil)
}
答案 1 :(得分:0)
帖子中的提示不起作用,但是菜单设置方式的代码(不是因为推荐)。经过一番思考,我想出了一个更好的解决方法。由于该程序同时具有IM消息系统和支持的电子邮件系统,因此我执行了以下操作:
1。)将菜单中的支持按钮链接到新的视图控制器&故事板中。
2.。)通过1:1信使或电子邮件支持添加了联系选项
出于某种原因,当不尝试直接从幻灯片菜单中解除时,撰写邮件视图已从视图控制器中解除。不是最优雅的解决方案,但它有效。