Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFMailComposeViewController Not Editable in iOS 8 Xcode 6

Tags:

ios

swift

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?

like image 316
john doe Avatar asked May 09 '26 06:05

john doe


2 Answers

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)
    }
}
like image 141
Steve Rosenberg Avatar answered May 11 '26 22:05

Steve Rosenberg


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];
}
like image 25
Vincent Avatar answered May 11 '26 22:05

Vincent