【问题标题】:MFMailComposeViewController crashing on presentViewController on iOS 10.2MFMailComposeViewController 在 iOS 10.2 上的 presentViewController 上崩溃
【发布时间】:2017-01-16 23:20:02
【问题描述】:

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

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

到目前为止,我已经尝试过从 VC1 过渡到 VC2..

  1. 通过performSegueIdentifier
  2. 通过Storyboard ID
  3. 通过Storyboard ID 和UINavigationController(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 外观。 This帖子帮我解决了。

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

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
}

【问题讨论】:

    标签: ios swift mfmailcomposeviewcontroller messageui


    【解决方案1】:

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

    【讨论】:

    • 是的,我创建了一个带有自定义视图的自定义导航栏,它必须在 VC2 中。我同意你所说的,删除自定义导航栏,但是我怎样才能只为邮件编写器删除自定义导航栏而不影响 VC2 栏?
    • 是的,当我在AppDelegate 中注释掉UINavigationBar.appearance() 时,它起作用了
    • 我找到了解决方案。这篇文章帮助我解决了它stackoverflow.com/questions/15580405/…。非常感谢您为我指明了正确的方向!
    猜你喜欢
    • 2012-06-27
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多