iosswiftsprite-kitmfmailcomposeviewcontrollermessageui

App store Rejected me from the app crashing but it has never crashed for me through numerous testing


I submitted my app to the app store, but they rejected it saying that the app crashed when they clicked the feedback button which is a button that opens up a MFMailComposeViewController. The problem I am having is I have run it on many devices between the simulator and actual devices, yet I have never had this problem. I will post my functions for the feedback button below which I have called and are all connected to the button (Like I said it works completely fine every time I have tested it), and my question is: Am i doing something wrong in the code to where only they get the crash?

func giveFeedback()
{
    let email = ["info@website.com"]
    var fvc = view?.window?.rootViewController
    var cev = MFMailComposeViewController()
    cev.mailComposeDelegate = self
    cev.setToRecipients(email)
    cev.setSubject("MyApp")
    fvc?.presentViewController(cev, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!)
{
    controller.dismissViewControllerAnimated(true, completion: nil)
}

Also, I have imported MessageUI, and in the class I have my MFMailComposeViewControllerDelegate


Solution

  • One thing is that you don't call canSendMail. I believe that if you try to show the MFMailComposeViewController when mails are disabled, your app would crash.

    In your function you would use it for example like this:

    func giveFeedback(contextViewController: UIViewController) {
    
        if MFMailComposeViewController.canSendMail() {
            let email = ["info@website.com"]
            var cev = MFMailComposeViewController()
            cev.mailComposeDelegate = self
            cev.setToRecipients(email)
            cev.setSubject("MyApp")
            contextViewController.presentViewController(cev, animated: true, completion: nil)
        }
    }
    

    But it would be best to check the status earlier and display the button only if email is enabled on the device...