App crashes when dismiss mail composer and show a HUD - iphone

I have a button in my app, when press it, a MFMailComposerViewController will show up, and when the composer dismisses, a MBProgressHUD with a custom view will show to tell user whether the mail is sent successfully or not.
It works fine if I press send button in the composer, the mail will be sent, the composer will be dismissed and a HUD will show. However, if I press the cancel button in the composer view, the composer dismisses, but HUD doesn't show, and the app crashes.
Here are the Log of crash.
2012-02-02 22:49:34.821 App[5091:707] -[ViewController size]: unrecognized selector
sent to instance 0x319210
2012-02-02 22:49:34.831 App[5091:707] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[ViewController size]: unrecognized selector sent to instance 0x319210'
*** First throw call stack:
(0x340af8bf 0x342ff1e5 0x340b2acb 0x340b1945 0x340b27b8
0x3748cfa5 0xf051 0x203d1 0x37553f5b 0x374f393b 0x374f37bf
0x3746d81b 0x37472fb9 0x34bc4ba7 0x36ce3e8d 0x340822dd
0x340054dd 0x340053a5 0x30889fcd 0x37486743 0xe7a7 0xe74c)
terminate called throwing an exception
The ViewController is the controller that present the mail composer.
Here are some code I used:
-(void)showHUDWithMessage:(NSString *)msg
{
HUD = [[MBProgressHUD alloc]initWithWindow:self.window];
[self.window addSubview:HUD];
HUD.delegate = self;
UIImage *image;
NSString *labelTextToShow;
//Do something here
UIImageView *imageView = [[[UIImageView alloc]initWithImage:image]autorelease];
HUD.labelText = labelTextToShow;
HUD.customView = imageView;
HUD.mode = MBProgressHUDModeCustomView;
[HUD show:YES];
[HUD hide:YES afterDelay:3.0];
}
-(void)mailFriend:(id)sender
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc]init];
mailController.mailComposeDelegate = self;
[mailController setSubject:#"Mail Subject"];
NSString *emailBody = #"Message";
[mailController setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:mailController animated:YES];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString *msg;
switch (result) {
case MFMailComposeResultSent:
msg = #"Sent";
break;
case MFMailComposeResultFailed:
msg = #"Fail";
break;
case MFMailComposeResultCancelled:
msg = #"Cancelled";
break;
case MFMailComposeResultSaved:
msg = #"Cancelled";
break;
default:
break;
}
//Show HUD here
[self showHUDWithMessage:msg];
[self dismissModalViewControllerAnimated:YES];
[controller release];
}
Since if the mail is sent, the composer view can dismiss successfully, the HUD can also show correctly, I really don't know what's wrong here...
Thanks!

Most likely this is overreleasing memory issue. Enable NSZombie and test your app.
Couple of things:
Where have you created controller ? You are responsible to release objects that you own. You don't own controller object so don't release it:
[controller release]; // comment this line
in
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
Next:
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString *msg = nil; // If result is not equal to any of the case statements then you want to pass nil to [self showHUDWithMessage:msg];
switch (result) {
case MFMailComposeResultSent:
msg = #"Sent";
break;
case MFMailComposeResultFailed:
msg = #"Fail";
break;
case MFMailComposeResultCancelled:
msg = #"Cancelled";
break;
case MFMailComposeResultSaved:
msg = #"Cancelled";
break;
default:
break;
}
//Show HUD here
[self showHUDWithMessage:msg];
[self dismissModalViewControllerAnimated:YES];
[controller release];
}
and MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc]init]; in -(void)mailFriend:(id)sender autorelease or release it later. Although this has nothing to do with issue you might have.

Remove all reference to MBProgressHUD and put a simple NSLog in your method. I'll bet my bottom dollar MB is causing this.
If not, memory management is my obvious second choice here. Comment out [controller release];

Related

Closing a view after cancelling an email

I want to be able to send an email from my app, in which I have got that portion working. The problem is when I cancel sending an email (which is what I'm testing for now) the email part is dismissed but I'm left with a black screen which I can't seem to dismiss.
So this is what I have. I've created a class to handle the email part:
MailViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#interface MailViewController : UIViewController <MFMailComposeViewControllerDelegate>
#end
Implemented as follows:
#import "MailViewController.h"
#interface MailViewController ()
#end
#implementation MailViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
[mailer setMailComposeDelegate:self];
[mailer setSubject:#"Subject"];
NSMutableArray *toArray = [[NSMutableArray alloc] initWithObjects:#"email#gmail.com", nil];
[mailer setToRecipients:toArray];
[self presentViewController:mailer animated:YES completion:nil];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failuer" message:#"This device is unable to send emails" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
switch (result){
case MFMailComposeResultCancelled:
NSLog(#"Mail cancelled: you cancelled the operation and no email was sent");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail failed");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(#"Mail sent");
break;
default:
NSLog(#"Mail not sent");
break;
}
[controller dismissViewControllerAnimated:YES completion:nil];
}
#end
And all of this is shown from another view like so:
-(IBAction)sendMessage:(id)sender{
NSLog(#"Going to send an email....");
MailViewController *mail = [[MailViewController alloc] init];
[self.navigationController pushViewController:mail animated:YES];
}
So when I run all of this, the email program opens and I can do email stuff. I can select Cancel, then Delete Draft and the email program is removed. However, I'm left with a black screen which I can then select Back from the top navigation bar to return to the previous view.
I simply want the app to return to the view that shows the email program when an email is sent or cancelled (or whatever). I'm sure it's something simple I'm missing.
The problem is tat you are pushing a MailViewController and then dimissing, if you push you should pop the view controller.
MFMailComposeViewControllers should be presented modally, not pushed on the navigation stack. You also dont need a subclass, you can create an instance of MFMailComposeViewController directly:
-(IBAction)sendMessage:(id)sender{
NSLog(#"Going to send an email....");
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[self presentViewController:mail animated:YES completion:nil];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
switch (result){
case MFMailComposeResultCancelled:
NSLog(#"Mail cancelled: you cancelled the operation and no email was sent");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail failed");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(#"Mail sent");
break;
default:
NSLog(#"Mail not sent");
break;
}
[controller dismissViewControllerAnimated:YES completion:nil];
}
There's a couple architecture questions I have, but first - the TL;DR version:
[self.navigationController popViewControllerAnimated:NO];
You could also choose YES for the boolean, but judging on your implementation, that wouldn't result in something nice. Put that in the delegate call for completion.
However, why not just have whatever's pushing MailViewController onto the stack handle the job of being the MFMailComposeViewControllerDelegate? You're doing nothing here that requires a completely new view controller be pushed onto the stack.

MFMailComposeViewController's delegate not handling the CANCEL button [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Action sheet doesn't display when the MFMailComposeViewController's cancel button is tapped
I've implemented standard mail functionality in my app according to the code sample provided by Apple.
I'm setting up the delegate as follows:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
and I'm implementing
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
Hitting the Send button invokes the delegate and it all works fine. However, hitting the Cancel button doesn't call the delegate and it just dims the view; the app hangs right there.
After reading similar threads here, I've been thinking that the view could be off-screen for some reason which is beyond my comprehension at this point. Note that the view is being created programmatically and is not using a xib file.
Any thoughts or ideas ?
You need to implement mailComposeController:didFinishWithResult:error delegate. And in that you dismiss the view which is showing your mail view. If you have opened the mail view as a modalView, then the way to dismiss this is -
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
if(error) NSLog(#"ERROR - mailComposeController: %#", [error localizedDescription]);
[self dismissModalViewControllerAnimated:YES];
return;
}
It may be helpful to you
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
//NSLog(#"Result: canceled");
break;
case MFMailComposeResultSaved:
//NSLog(#"Result: saved");
break;
case MFMailComposeResultSent:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Result" message:#"Mail Sent Successfully" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
break;
case MFMailComposeResultFailed:
//NSLog(#"Result: failed");
break;
default:
//NSLog(#"Result: not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
Try to add even simple delegate :
[picker setDelegate:self];

UIActionSheet to open up Mail Application iPhone

This issue is something which has me stumped, so hopefully someone can help. I have an UIActionSheet on a view which has three options in. One which takes my user to a new view, one to share via email and one to share via SMS.
I have the UIActionSheet created which works without issue, the new view part of the AlertSheet also works. I have imported the Message.UI framework and set up the mail and SMS pickers and composers which are fine. However, I am having trouble setting the two 'buttons' on the UIActionSheet to open up the mail and SMS.
Normally i would do this through interface builder and connect a UIButton to the actions I have created, but because this is a UIActionSheet it can't be done that way. Sorry for the LONG code but I felt I needed to show everything, so please see below;
-(IBAction)showActionSheet {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Choose an Option" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Application Support",#"Share Via Email",#"Share Via SMS",nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0) {
AppSupportView *controller = [[AppSupportView alloc] initWithNibName:#"AppSupportView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
if(buttonIndex == 1) {
}
if(buttonIndex == 2) {
}
}
- (void)dealloc {
[feedbackMsg release];
[super dealloc];
}
- (void)viewDidUnload {
self.feedbackMsg = nil;
}
-(IBAction)showMailPicker:(id)sender {
// The MFMailComposeViewController class is only available in iPhone OS 3.0 or later.
// So, we must verify the existence of the above class and provide a workaround for devices running
// earlier versions of the iPhone OS.
// We display an email composition interface if MFMailComposeViewController exists and the device
// can send emails. Display feedback message, otherwise.
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
if (mailClass != nil) {
//[self displayMailComposerSheet];
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail]) {
[self displayMailComposerSheet];
}
else {
feedbackMsg.hidden = NO;
feedbackMsg.text = #"Device not configured to send mail.";
}
}
else {
feedbackMsg.hidden = NO;
feedbackMsg.text = #"Device not configured to send mail.";
}
}
-(IBAction)showSMSPicker:(id)sender {
// The MFMessageComposeViewController class is only available in iPhone OS 4.0 or later.
// So, we must verify the existence of the above class and log an error message for devices
// running earlier versions of the iPhone OS. Set feedbackMsg if device doesn't support
// MFMessageComposeViewController API.
Class messageClass = (NSClassFromString(#"MFMessageComposeViewController"));
if (messageClass != nil) {
// Check whether the current device is configured for sending SMS messages
if ([messageClass canSendText]) {
[self displaySMSComposerSheet];
}
else {
feedbackMsg.hidden = NO;
feedbackMsg.text = #"Device not configured to send SMS.";
}
}
else {
feedbackMsg.hidden = NO;
feedbackMsg.text = #"Device not configured to send SMS.";
}
}
// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"My BMR Index Rating from Total:Health App"];
// Set up recipients
//NSArray *toRecipients = [NSArray arrayWithObject:#""];
//[picker setToRecipients:toRecipients];
NSString *emailSharing = #"I Just discovered that I have a Target Heart Rate of";
// Fill out the email body text
[picker setMessageBody:emailSharing isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
// Displays an SMS composition interface inside the application.
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSString *SMSShare = #"I Just discovered that I have a Target Heart Rate of";
// Fill out the email body text
picker.body = SMSShare;
[self presentModalViewController:picker animated:YES];
[picker release];
}
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the
// message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
feedbackMsg.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
feedbackMsg.text = #"Result: Mail sending canceled";
break;
case MFMailComposeResultSaved:
feedbackMsg.text = #"Result: Mail saved";
break;
case MFMailComposeResultSent:
feedbackMsg.text = #"Result: Mail sent";
break;
case MFMailComposeResultFailed:
feedbackMsg.text = #"Result: Mail sending failed";
break;
default:
feedbackMsg.text = #"Result: Mail not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
// Dismisses the message composition interface when users tap Cancel or Send. Proceeds to update the
// feedback message field with the result of the operation.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
feedbackMsg.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MessageComposeResultCancelled:
feedbackMsg.text = #"Result: SMS sending canceled";
break;
case MessageComposeResultSent:
feedbackMsg.text = #"Result: SMS sent";
break;
case MessageComposeResultFailed:
feedbackMsg.text = #"Result: SMS sending failed";
break;
default:
feedbackMsg.text = #"Result: SMS not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
#end
The issue is obviously that I dont know how to proceed with the (if buttonIndex ==1) etc piece of code to open the mail and SMS
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0) {
AppSupportView *controller = [[AppSupportView alloc] initWithNibName:#"AppSupportView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
if(buttonIndex == 1) {
}
if(buttonIndex == 2) {
}
}
Any help would be appreciated.
Thanks
looks like all your needed methods are there already..
just add [self showMailPicker:nil] or [self showSMSPicker:nil] to
if(buttonIndex == 1) {
}
if(buttonIndex == 2) {
}
if your second button from the top is your sms button, add showSMSPicker to buttonIndex == 1

Sending email message from the app using MFMailComposeViewController in MessageUI on iPhone

I'm a software developer, and I'm making an application for the email message and I have the following code:
// Header file
// importing the MessageUI framework
#import <MessageUI/MessageUI.h>
// adding the delegate functionality to the class (<MFMailComposeViewControllerDelegate>)
#interface TutorialProjectViewController : UIViewController <MFMailComposeViewControllerDelegate> {
}
- (IBAction)pressTheMailButtonDudeFunction:(id)sender
// Implementation file
- (IBAction)pressTheMailButtonDudeFunction:(id)sender {
// allocatind new message composer window
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
// setting a delegate method to "self"
mc.mailComposeDelegate = self;
// pre-populating the message subject
[mc setSubject:#"Send me a message"];
// adding content of the message as a plain text
[mc setMessageBody:#"Send me a message is you like this tutorial :)" isHTML:NO];
// adding content of the message as an HTML
[mc setMessageBody:#"<p>Send me a message is you like this tutorial :)<p>" isHTML:YES];
// adding recipients
[mc setToRecipients:[NSArray arrayWithObjects:#"Fuerte <info#fuerte.cz>", #"info#xprogress.com", nil]];
// adding recipients for a send copy to (arrayWithObject or arrayWithObjects)
[mc setCcRecipients:[NSArray arrayWithObject:#"test#example.com"]];
// adding hidden recipients
[mc setBccRecipients:[NSArray arrayWithObject:#"test#example.com"]];
// adding image attachment
// getting path for the image we have in the tutorial project
NSString *path = [[NSBundle mainBundle] pathForResource:#"Extra_Xcode_100x100" ofType:#"png"];
// loading content of the image into NSData
NSData *imageData = [NSData dataWithContentsOfFile:path];
// adding the attachment to he message
[mc addAttachmentData:imageData mimeType:#"image/png" fileName:#"Collection"];
// setting different than the default transition for the modal view controller
[mc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
/*
Modal view controllers transitions:
UIModalTransitionStyleCoverVertical => pops up from the bottom, default transition
UIModalTransitionStyleCrossDissolve => fade on the screen
UIModalTransitionStyleFlipHorizontal => page flip
*/
// displaying our modal view controller on the screen (of course animated has to be set on YES if you want to see any transition)
[self presentModalViewController:mc animated:YES];
// releasing the controller
[mc release];
}
// delegate function callback
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
// switchng the result
switch (result) {
case MFMailComposeResultCancelled:
NSLog(#"Mail send canceled.");
/*
Execute your code for canceled event here ...
*/
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved.");
/*
Execute your code for email saved event here ...
*/
break;
case MFMailComposeResultSent:
NSLog(#"Mail sent.");
/*
Execute your code for email sent event here ...
*/
break;
case MFMailComposeResultFailed:
NSLog(#"Mail send error: %#.", [error localizedDescription]);
/*
Execute your code for email send failed event here ...
*/
break;
default:
break;
}
// hide the modal view controller
[self dismissModalViewControllerAnimated:YES];
}
And I'm not getting the proper answer... Is it a right code?
Be sure that you included the MessageUI framework into your iOS project. Within Xcode 4, you can include the framework by selecting your project in the left column. Then selecting the Tab "Build Phases". Here you can click on the arrow left of "Link Binary With Libraries" and you see the list of frameworks which are already included to your app. If MessageUI.framework is missing - just add it there.
The code you posted looks like a complete tutorial code snipped ... so only use the code you need ... and add more features to it step by step. This way you'll see where you add a buggy line of code. Maybe there is no image "Extra_Xcode_100x100.png" in your app bundle.
So, here's a "minimal" MFMailComposeViewController:
- (IBAction)showMinimalModalMailView:(id)sender {
// get a new new MailComposeViewController object
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
// his class should be the delegate of the mc
mc.mailComposeDelegate = self;
// set a mail subject ... but you do not need to do this :)
[mc setSubject:#"This is an optional mail subject!"];
// set some basic plain text as the message body ... but you do not need to do this :)
[mc setMessageBody:#"This is an optional message body plain text!" isHTML:NO];
// set some recipients ... but you do not need to do this :)
[mc setToRecipients:[NSArray arrayWithObjects:#"first.address#test.com", #"second.address#test.com", nil]];
// displaying our modal view controller on the screen with standard transition
[self presentModalViewController:mc animated:YES];
// be a good memory manager and release mc, as you are responsible for it because your alloc/init
[mc release];
}
I had the same issue, every time ran the app on sending the message it crashed; I found that if I removed
[mc setToRecipients:[NSArray arrayWithObjects:#"first.address#test.com", #"second.address#test.com", nil]];
it works fine and just asks me for the email address.
For sending email message from the app your device should be configure for email service.
// importing the MessageUI framework
#import <MessageUI/MessageUI.h>
// adding the delegate functionality to the class (<MFMailComposeViewControllerDelegate>)
#interface ViewController : UIViewController <MFMailComposeViewControllerDelegate> {
}
- (IBAction)sendEMailClick:(id)sender {
//check mail service is configure to your device or not.
if ([MFMailComposeViewController canSendMail]) {
// get a new new MailComposeViewController object
MFMailComposeViewController * composeVC = [MFMailComposeViewController new];
// his class should be the delegate of the composeVC
[composeVC setDelegate:self];
// set a mail subject ... but you do not need to do this :)
[composeVC setSubject:#"This is an optional mail subject!"];
// set some basic plain text as the message body ... but you do not need to do this :)
[composeVC setMessageBody:#"This is an optional message body plain text!" isHTML:NO];
// set some recipients ... but you do not need to do this :)
[composeVC setToRecipients:[NSArray arrayWithObjects:#"first.address#test.com", #"second.address#test.com", nil]];
// Present the view controller modally.
[self presentViewController:composeVC animated:true completion:nil];
} else {
NSLog(#"Mail services are not available or configure to your device");
}
}
after email is send or cancel click in MFMailComposeViewController delegate methode of MFMailComposeViewControllerDelegate is call, so there you can check email send status.
#pragma mark - MFMailComposeViewControllerDelegate Methode.
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error {
switch (result) {
case MFMailComposeResultCancelled:
NSLog(#"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(#"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(#"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(#"Mail sent failure: %#",error.description);
break;
}
// Dismiss the mail compose view controller.
[controller dismissViewControllerAnimated:true completion:nil];
}

Using MFMailComposeViewController to send a mail, get “EXC_BAD_ACCESS” when dismissing the modal view controller

I am sending an email from my iPhone app using MFMailComposeViewController. This works fine but after sending or canceling I need to dismiss the modalViewController. When I do this I get a Program received signal: “EXC_BAD_ACCESS”. This is not very descriptive... Please help!!
This is the code for creating the mail and the modalViewController
-(void)sendFavMail:(NSString *)body{
MFMailComposeViewController* mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:#"Favorites List"];
[mailViewController setMessageBody:body isHTML:YES];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
And this is the code for the delegate, dismissing the modalviewcontroller:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"Cancelled sending");
break;
case MFMailComposeResultSaved:
NSLog(#"Message Saved");
break;
case MFMailComposeResultSent:
NSLog(#"Message Sent");
break;
case MFMailComposeResultFailed:
NSLog(#"Sending Failed");
break;
default:
NSLog(#"Message not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
Thanks for your help!!
Darn, fixed it myself :-)
I released an object in the body of the message before sending/cancelling. What I did to fix it is to declare this body object autoreleased. And what do you know? IT WORKS!
Just answered my own question...