MFMailComposeViewController() 未在 UIAlertAction 中被解除

MFMailComposeViewController() not dismissed inside 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)
            
        }
    }  
}


一切正常。发送邮件 window 打开,邮件也被发送了,但是当按下 'cancel' 和 'send' 按钮时,MFMailComposeViewController() 没有被关闭(必须按顺序向下滑动关闭它)

有什么问题吗?

将此委托置于函数之外并置于控制器内class。 另外,像这样解散controller.dismiss(animated: true)

private extension SettingsListViewController {
 func mailComposeController(_ controller: MFMailComposeViewController,
                               didFinishWith result: MFMailComposeResult, error: Error?) {
        controller.dismiss(animated: true)
    }
}