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?
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)
}
}
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With