ios - MFMailComposeViewController() 未在 UIAlertAction 内解除
问题描述
我在 UIAlertController 中打开了 MFMailComposeViewController,代码如下所示:
import StoreKit
import MessageUI
class SettingsListViewController: UIViewController, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate {
// Some code adding the UITableView and etc
// ...
}
private extension SettingsListViewController {
func didSelectShareCell(shareSectionCell: ShareSectionCell, _ tableView: UITableView, cellForRowAt indexPath: IndexPath) {
switch shareSectionCell {
// Some other cases...
case .rate:
let actionSheet = UIAlertController(title: "Feedback", message: "Are you enjoing the app?", preferredStyle: .alert)
actionSheet.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))
actionSheet.addAction(UIAlertAction(title: "Yes, i love it", style: .default, handler: { action in
SKStoreReviewController.requestReview()
}))
actionSheet.addAction(UIAlertAction(title: "No, this sucks", style: .default, handler: { action in
guard MFMailComposeViewController.canSendMail() else {
// Alert info user
return
}
let composer = MFMailComposeViewController()
composer.mailComposeDelegate = self
composer.delegate = self
composer.setToRecipients(["my mail"])
composer.setSubject("i'm mad")
composer.setMessageBody("Hey, i love your app but...", isHTML: false)
self.present(composer, animated: true)
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult, error: Error?) {
self.dismiss(animated: true)
}
}))
present(actionSheet, animated: true)
}
}
}
一切正常。发送邮件窗口打开,邮件也被发送,但是当按下“取消”和“发送”按钮时,MFMailComposeViewController() 没有被关闭(必须向下滑动才能关闭它)
有什么问题?
解决方案
将此委托放在函数外部和控制器类内部。另外,像这样解雇controller.dismiss(animated: true)
private extension SettingsListViewController {
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}
推荐阅读
- arrays - 更有效的方法来分割重叠的间隔,然后合并重复
- php - 将 ACF 管理列添加到自定义帖子类型
- php - 如何在遗留系统中测试 json-api 的排序
- oracle11g - PHP 5.2.0-8 上的 oci_connect 不适用于 Oracle 11g
- wagtail - 无法让联合查询在 Wagtail 中的不同模型中工作
- sql-server - 如何修复 SSIS 中缺少的 SQL 连接管理器
- r - 通过数据帧循环函数,区分,然后在原始数据帧中按列组合
- php - 遍历 JSON 请求的多个页面(Guzzle、Laravel、PHP)
- blazor - 当我在表单中选择另一个文本框时,羽毛笔编辑器的内容被清除
- python - 我的代码返回“命令 '['python3']' 2 秒后超时”