MFMailComposeViewController 在 iOS 10.2 上的 presentViewController 上崩溃

MFMailComposeViewController crashing on presentViewController on iOS 10.2

好吧,这是一个非常小的问题,我已经花了几个小时研究并试图找出应用程序崩溃的原因。

假设我有两个视图控制器 VC1、VC2,我正在从 VC2 调用 MFMailComposeViewController

到目前为止,我已经尝试从 VC1 转换到 VC2..

  1. 通过performSegueIdentifier
  2. 通过Storyboard ID
  3. 通过 Storyboard IDUINavigationController(rootViewController: vc2)

但没有任何效果。我什至尝试将 UINavigationViewController 嵌入 VC2,但也没有成功。

下面是VC2

中的IBAction方法
@IBAction func sendEmail(sender: AnyObject) {
    if MFMailComposeViewController.canSendMail() {
        let mailComposerVC = configuredMailComposeViewController()
        presentViewController(mailComposerVC, animated: true, completion: nil) // CRASH
    } else {
        showSendMailErrorAlert()
    }
}


func configuredMailComposeViewController() -> MFMailComposeViewController {

    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self

    mailComposerVC.setToRecipients(["abc@abc.com"])
    mailComposerVC.setSubject("Reg: ")

    return mailComposerVC
}

func showSendMailErrorAlert() {
    let alert = UIAlertController(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", preferredStyle: .Alert)
    presentViewController(alert, animated: true, completion: nil)
}

所有网点和活动参考也很好。

崩溃日志

[__NSCFNumber pointSize]: unrecognized selector sent to instance 0xb0000000000000e5
2017-01-16 16:52:55.887082 Sample[2507:671461] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber pointSize]: unrecognized selector sent to instance 0xb0000000000000e5'

已解决:

问题出在自定义导航栏上。我在呈现 MFMailComposeViewController 时重置了 UINavigationBar 外观,并在关闭时将其重新设置。 Thispost帮我解决了

我在全局文件中创建了以下两种方法。

static func applyGlobalNavigationBarAppearance() {
    UINavigationBar.appearance().barTintColor = UIColor.blueColor()
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor(), NSFontAttributeName: UIFont.systemFontSize()]
}

static func applyMailNavigationBarAppearance() {
    UINavigationBar.appearance().barTintColor = UIColor.whiteColor()
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = nil
}

奇怪!我的猜测是您通过 UIAppearance 设置了一些东西(字体?),并且邮件编辑器是第一次引用此外观 属性。您的项目是否使用 UIAppearance(例如 UINavigationBar.appearance)?如果是这样,请暂时将它们注释掉。看看是否能解决问题,然后找出问题所在。