Search code examples
iosswiftiphonemfmailcomposeviewcontrollerios16

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


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?


Solution

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