MFMailComposeViewController在iOS 13模拟器和设备中的行为不同

MFMailComposeViewController在iOS 13模拟器和设备中的行为不同,ios,swift,ios13,mfmailcomposeviewcontroller,xcode11,Ios,Swift,Ios13,Mfmailcomposeviewcontroller,Xcode11,我正在尝试在应用程序中显示MFMailComposeViewController if MFMailComposeViewController.canSendMail() { let mailComposeViewController = MFMailComposeViewController() mailComposeViewController.navigationBar.tintColor = .white mailComposeViewController.mai

我正在尝试在应用程序中显示
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时,
MFMailComposeViewController
会立即自动关闭

Xcode控制台中也会出现以下错误

[Common][FBSSystemService][0x5f27]处理的打开请求时出错 com.apple.MailCompositionService:{ 用户信息={ FBSOpenApplicationRequestID=0x5f27; } UnderlineError=;}2019-11-01 14:40:05.214158+0530邮件撰写[11289:262267][Assert]连接 请求在不恢复我们的_serviceSessionConnection连接的情况下无效。 这是一个错误。2019-11-01 14:40:05.216901+0530 MailCompose[11289:262054][General]#合成服务 _serviceViewControllerReady:n错误域=\u UIViewServiceInterfaceErrorDomain代码=0

我猜这个奇怪的错误是一个Xcode错误。但是我如何修复背景颜色和发送按钮不显示在设备中

这就是我设置所有导航栏相关样式的方式

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]
}

在显示前添加这行代码。它会正常工作。这是iOS 13的一个变化

mailController.modalPresentationStyle = .fullScreen

Mail composer会立即解散的原因是,您实际上无法从模拟器发送电子邮件。实现与iOS本身不同


我猜这里发生的事情是,虽然模拟器实现只使用一些普通的UI元素,但本机iOS上的
MFMailComposeViewController
实际上是托管的类似于
UIDocumentPickerViewController
UIActivityViewController
。这意味着屏幕截图和尝试遍历视图树是不可能的,因为视图不是应用程序的实际部分。它们这样做是因为这些控制器包含用户私有信息。托管视图控制器不允许自定义,并且不符合全局
UINavigationBar.appearance()
。这将解释为什么它会出现在模拟器中而不是本机设备上。

这是iOS 13的新UI样式。您可以在情节提要或手动设置中禁用它。

我在iOS 13.3上遇到了完全相同的问题。你找到解决方案了吗?@inankupeli不幸的是没有。我也在苹果开发者论坛上发布了同样的问题,但也没有回应。@Isuru你找到解决方案了吗?@Isuru在你提到的问题中,你试图在模拟器中运行它,但是,这无法在模拟器中进行测试。您需要一个设备来实现这一点,iOS 13中的默认模式演示是页面工作表,您能否尝试将模式演示更改为全屏,并查看是否获得相同的行为?这在设备中也有同样的响应吗?