如何解决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",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)
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。