1

Well, this is very minor issue on which I have already spent couple of hours researching and trying to figure out why the app is crashing.

Let's say I've two view controllers VC1, VC2 and I'm calling MFMailComposeViewController from VC2.

So far I have tried transitioning from VC1 to VC2..

  1. via performSegueIdentifier
  2. via Storyboard ID
  3. via Storyboard ID with UINavigationController(rootViewController: vc2)

but nothing worked. I even tried embedding UINavigationViewController to the VC2 but no luck either.

Below is the IBAction method in VC2

@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)
}

All outlets and event references are also good.

Crash log

[__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'

Solved:

The issue is with the custom navigation bar. I have reset the UINavigationBar appearance when presenting MFMailComposeViewController and setting it back on dismiss. This post helped me solve it.

I have created below two methods in a global file.

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
}
Community
  • 1
  • 1
Srujan Simha
  • 3,637
  • 8
  • 42
  • 59

1 Answers1

1

Strange! My guess here is that you have set something (a font?) badly via UIAppearance and the mail composer is the first time this appearance property is being referenced. Does your project use UIAppearance (e.g. UINavigationBar.appearance)? If so, comment them out for now. See if that fixes the problem, then figure out which call is the culprit.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
  • Yes, I created a custom navigation bar with custom view, it has to be there in VC2. I agree with what you've said, removing the custom navigation bar, but how can I remove the custom navigation bar only for the mail composer without affecting VC2 bar? – Srujan Simha Jan 17 '17 at 14:58
  • And yes, it worked when I commented out the `UINavigationBar.appearance()` in `AppDelegate` – Srujan Simha Jan 17 '17 at 15:10
  • 1
    I figured out the solution. This post helped me solve it http://stackoverflow.com/questions/15580405/override-uiappearance-property-for-mfmailcomposeviewcontroller. Thanks a lot for pointing me to the right direction! – Srujan Simha Jan 17 '17 at 15:20