我正在尝试在应用程序中显示MFMailComposeViewController
。
if MFMailComposeViewController.canSendMail() {
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = .white
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients(["support@gmail.com"])
mailComposeViewController.setSubject("Feedback")
present(mailComposeViewController, animated: true)
} else {
print("This device is not configured to send email. Please set up an email account.")
}
在iOS 12中,它可以正常显示,无论是在模拟器还是设备上。
但是当我在运行相同的项目时,它在运行iOS 13的设备上看起来像这样。
导航栏颜色消失了。发送按钮也看不见了。所以我添加了
mailComposeViewController.navigationBar.backgroundColor = .mv_primary
,但它仍然不能在设备上显示。奇怪的是,背景颜色在模拟器中显示出来了。然而,有一个奇怪的行为。当我在模拟器中运行它时,
MFMailComposeViewController
立即自动关闭。
以下错误也会显示在Xcode控制台中。``` [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 ```
我猜这个奇怪的dismiss错误是Xcode的一个bug。但是如何修复设备上的背景颜色和发送按钮没有显示出来呢?
这是我设置所有导航栏相关样式的方法。
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]
}