Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

swift - MFMailComposeViewController behaves differently in iOS 13 simulator and device

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

mailController.modalPresentationStyle = .fullScreen

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...