0

Present an mail compose view controller modally in UIKit environment

private func presentMailCompose() {
    guard MFMailComposeViewController.canSendMail() else {
        return
    }
    
    // The following windows is the problem !!!  It deprecated in iOS 15.0
    
    let vc = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
    
    let composeVC = MFMailComposeViewController()
    composeVC.mailComposeDelegate = mailComposeDelegate
    
    // Customize here
    
    vc?.present(composeVC, animated: true)
}
HangarRash
  • 7,314
  • 5
  • 5
  • 32
jchan12345
  • 31
  • 4
  • The solution will need to use UIWindowsScene.windows. Hope someone can present an example. Thanks. – jchan12345 Apr 04 '23 at 16:59
  • 1
    Do not edit your title to add a comment. Post a comment instead. But note that many of the answers in the referenced duplicate do apply. Just avoid any answers that make use of `UIApplication.shared.windows`. – HangarRash Apr 04 '23 at 17:09

0 Answers0