john doe
john doe

Reputation: 9660

MFMailComposeViewController Not Editable in iOS 8 Xcode 6

I am using the following code to show the email sheet. The sheet shows up but I cannot edit the subject, body. I cannot even press the cancel or send 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?

Upvotes: 3

Views: 2216

Answers (3)

LAOMUSIC ARTS
LAOMUSIC ARTS

Reputation: 628

I come with this simple solution:

//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(["[email protected]"])

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

}

P.S.: "setToRecipients" works on a real device only, not in the simulator !

Upvotes: 0

Vincent
Vincent

Reputation: 4409

I'm having the same problem under Xcode6 and iOS8.

However I noticed that this appears to be a emulator problem. The following code works on iOS8, but only on the device (so not on the 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:@"[email protected]"]]];

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

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

Upvotes: 1

Steve Rosenberg
Steve Rosenberg

Reputation: 19524

Here is the working code from one of my projects. Be sure to work with the form on an iOS device and not in the 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 = ["[email protected]"]
        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)
    }
}

Upvotes: 4

Related Questions