MFMailComposeViewController behaves differently in iOS 13 simulator and device
Asked Answered
A

3

20

I'm trying to display MFMailComposeViewController in an app.

if MFMailComposeViewController.canSendMail() {
    let mailComposeViewController = MFMailComposeViewController()
    mailComposeViewController.navigationBar.tintColor = .white
    mailComposeViewController.mailComposeDelegate = self
    mailComposeViewController.setToRecipients(["[email protected]"])
    mailComposeViewController.setSubject("Feedback")
    present(mailComposeViewController, animated: true)
} else {
    print("This device is not configured to send email. Please set up an email account.")
}

In iOS 12, it shows up without an issue. In both simulator and device.

enter image description here

But when I run the same project on a device running iOS 13, it looks like this.

enter image description here

The navigation bar color is gone. Also the send button is also invisible.

So I added mailComposeViewController.navigationBar.backgroundColor = .mv_primary but it still doesn't show on the device. Strangely the background color shows in the simulator.

However there's a strange behavior. The MFMailComposeViewController immediately dismisses by itself when I run it in the simulator.

enter image description here

The following error also shows up in the Xcode console.

[Common] [FBSSystemService][0x5f27] Error handling open request for com.apple.MailCompositionService: { userInfo = { FBSOpenApplicationRequestID = 0x5f27; } underlyingError = ; } 2019-11-01 14:40:05.214158+0530 MailCompose[11289:262267] [Assert] Connection request invalidated without resuming our _serviceSessionConnection. This is an error. 2019-11-01 14:40:05.216901+0530 MailCompose[11289:262054] [General] #CompositionServices _serviceViewControllerReady: NSError Domain=_UIViewServiceInterfaceErrorDomain Code=0

I guess the weird dismiss error is a Xcode bug. But how do I fix the background color and the send button not showing up in the device?

This is how I set all the navigationbar related styles.

UINavigationBar.appearance().barTintColor = .mv_primary
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
if #available(iOS 11.0, *) {
    UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}

Demo project

Alderman answered 1/11, 2019 at 9:32 Comment(4)
I'm having the exact same problem on iOS 13.3. Did you find a solution for this?Softcover
@inankupeli Unfortunately no. I posted the same question on Apple Developer forums as well but no response there as well.Alderman
@Alderman have you found out any solution?Bronco
@Alderman In the question you mentioned that you are trying to run it in the simulator, however this cannot be tested in the simulator you need a device for that, the default modal presentation in iOS 13 is page sheet, can you try changing the modal presentation to fullscreen and see if you get the same behavior? Does this respond the same way in device as well?Scrape
D
1

Add this line of code before present it. It will work normal. This a change in iOS 13

mailController.modalPresentationStyle = .fullScreen
Dante answered 20/5, 2020 at 6:53 Comment(0)
W
1

The reason why the Mail composer dismisses immediately is because you can't actually send an email from the simulator. The implementation is different from iOS itself.

What I guess is happening here is that while the simulator implementation uses just some normal UI elements, the MFMailComposeViewController on native iOS is actually hosted like UIDocumentPickerViewController or UIActivityViewController. This means screenshots and trying to traverse the view tree is impossible, because the view is not an actual part of your application. They do that because these controllers contain user private information. Hosted view controller do NOT allow for customization, and do not comply with your global UINavigationBar.appearance(). This would explain why it does show up in the simulator and not on your native device.

Widgeon answered 21/5, 2020 at 20:29 Comment(0)
D
1

This is new UI Style from iOS 13. You can disable it in Storyboard or set manual. Presenting modal in iOS 13 fullscreen

Devoe answered 3/7, 2020 at 13:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.