MFMailComposeViewController not editable in iOS 8 Xcode 6

I am using the following code to show an email sheet. The sheet appears, but I cannot edit the theme, body. I can't even hit the cancel or submit buttons. Here is my implementation:

class PeopleListTableViewController: UITableViewController,SWTableViewCellDelegate,UINavigationControllerDelegate,MFMailComposeViewControllerDelegate, NSXMLParserDelegate {

 func showEmailSheet(person :Person) {

        if MFMailComposeViewController.canSendMail() {

            let mailViewController = MFMailComposeViewController()
            mailViewController.mailComposeDelegate = self

            mailViewController.setToRecipients([person.email!])

            self.presentViewController(mailViewController, animated: true, completion: nil)

        }
    }

      

What am I doing wrong?

+3


source to share


3 answers


Here is a working code from one of my projects. Make sure to work with the form on an iOS device, not in a simulator.



import UIKit
import MessageUI

class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
    @IBAction func launchEmail(sender: AnyObject) {

        var emailTitle = "Feedback"
        var messageBody = "Feature request or bug report?"
        var toRecipents = ["youraddress@gmail.com"]
        var mc: MFMailComposeViewController = MFMailComposeViewController()
        mc.mailComposeDelegate = self
        mc.setSubject(emailTitle)
        mc.setMessageBody(messageBody, isHTML: false)
        mc.setToRecipients(toRecipents)

        self.presentViewController(mc, animated: true, completion: nil)
    }

    func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
        switch result.value {
        case MFMailComposeResultCancelled.value:
            println("Mail cancelled")
        case MFMailComposeResultSaved.value:
            println("Mail saved")
        case MFMailComposeResultSent.value:
            println("Mail sent")
        case MFMailComposeResultFailed.value:
            println("Mail sent failure: %@", [error.localizedDescription])
        default:
            break
        }
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}

      

+4


source


I have the same problem in Xcode6 and iOS8.

However, I noticed that this is an emulator issue. The following code works on iOS8, but only on a device (not an emulator)!



MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
if([MFMailComposeViewController canSendMail]) {
    composer.mailComposeDelegate = self;

    messageContent=[NSString stringWithFormat:@"Bla bla"];

    [composer setSubject:@"The subject"];
    [composer setMessageBody:messageContent isHTML:NO];
    [composer setToRecipients:[NSArray arrayWithObject:[NSString stringWithFormat:@"Vincent@xxxxx.com"]]];

    [composer setCcRecipients:nil];
    [composer setBccRecipients:nil];
    [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

    [self presentViewController:composer animated:YES completion:nil];
}

      

+1


source


I came up with a simple solution like this:

//outlet & btns
@IBOutlet weak var forgotEmail: UITextField!

@IBAction func resetPW(sender: AnyObject) {
    // send email
    var mailer = MFMailComposeViewController()
    mailer.mailComposeDelegate = self
    mailer.setSubject("Forgot Password")
    mailer.setToRecipients(["admin@someMail.com"])

    presentViewController(mailer, animated:true, completion: nil)

}

      

PS: "setToRecipients" only works on real device, not simulator!

0


source







All Articles