MFMailComposeViewController delegate method not working in iOS 16.0 or above device when device orientation is in portrait mode

huangapple go评论59阅读模式
英文:

MFMailComposeViewController delegate method not working in iOS 16.0 or above device when device orientation is in portrait mode

问题

我在另一个视图控制器的顶部显示了MFMailComposeViewController,而该视图控制器支持横向和纵向方向。以下是我尝试的方法:

if MFMailComposeViewController.canSendMail() {
    let mc = MFMailComposeViewController()
    mc.mailComposeDelegate = self
    mc.setSubject(emailTitle)
    mc.setMessageBody(messageBody, isHTML: false)
    mc.setToRecipients(toRecipents)
    mc.modalPresentationStyle = .fullScreen
    
    // 展示MailComposeViewController
    self.present(mc, animated: true)
}

这段代码完全正常工作,我还添加了类似以下的委托方法:

extension RateViewController: MFMailComposeViewControllerDelegate {
    
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        switch result {
        case .cancelled:
            print("邮件已取消")
        case .saved:
            print("邮件已保存")
        case .sent:
            print("邮件已发送")
        case .failed:
            print("邮件发送失败:\(error?.localizedDescription ?? "")")
        default:
            break
        }
        
        // 关闭邮件界面
        controller.dismiss(animated: true) {
            self.dismiss(animated: true)
        }
    }
}

我在多台iPhone设备上测试了这个代码,除了iOS 16.1.2设备之外,委托方法都正常调用。在iOS 16.1.2设备上,当设备处于横向方向时委托方法也能正常调用,但在纵向方向时却没有调用委托方法。这可能的原因是什么呢?

英文:

I present MFMailComposeViewController on top of another viewController and that viewController support both landscape and portrait orientation.
Here is the way I tried

if MFMailComposeViewController.canSendMail() {
                let mc = MFMailComposeViewController()
                mc.mailComposeDelegate = self
                mc.setSubject(emailTitle)
                mc.setMessageBody(messageBody, isHTML: false)
                mc.setToRecipients(toRecipents)
                mc.modalPresentationStyle = .fullScreen
               
                // Present MailComposeViewController
                self.present(mc, animated: true)
            }

this work totally fine and also I added delegate method too like this

extension RateViewController: MFMailComposeViewControllerDelegate{
    
    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
        switch result {
        case .cancelled:
            print("Mail cancelled")
        case .saved:
            print("Mail saved")
        case .sent:
            print("Mail sent")
        case .failed:
            print("Mail sent failure: \(error?.localizedDescription ?? "")")
        default:
            break
        }
        
        // Close the Mail Interface
        controller.dismiss(animated: true) {
            self.dismiss(animated: true)
        }
        
    }
}

I tested this one in more than one iPhone devices, other than iOS 16.1.2 device delegate method call properly, in iOS 16.1.2 device it also calling properly when device in landscape orientation, for portrait orientation it is not call the delegate method. what can be the possible reason for this?

答案1

得分: 0

似乎是 iOS 版本 16.1.2 的一个 bug,在我更新那些设备后,它现在可以正常工作。

英文:

seems like it was a bug of iOS version 16.1.2 , after I update that devices now it works fine.

huangapple
  • 本文由 发表于 2023年2月24日 16:57:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554473.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定