1

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

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

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

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

但没有任何效果。我什至尝试嵌入UINavigationViewController到 VC2 但也没有运气。

下面是IBActionVC2中的方法

@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'

已解决

问题在于自定义导航栏。我UINavigationBar在呈现MFMailComposeViewController并将其重新设置为关闭时重置了外观。 这个帖子帮我解决了。

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

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

1 回答 1

1

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

于 2017-01-17T04:17:07.440 回答