tags:

views:

182

answers:

2

I am trying to add MFMailComposer to my iPhone app and not having much luck getting it to launch in my iPhone 2G. It always launches the email app to the accounts page and closes my app. Works like a charm in the simulator.

-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];

[self displayComposerSheet];

} -(void)displayComposerSheet {

Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
 // you have the MFMailComposeViewController class
 MFMailComposeViewController *picker =  [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

NSArray *mailArr = [[NSArray alloc] initWithObjects:self.sendTo,nil];  

[picker setSubject:@"Hello from iCamp America"];
[picker setToRecipients:mailArr];
NSString *emailBody = @"\n\n\email created with iCamp America\nwww.iCampAmerica.com";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];
[mailArr release];
}
else
{
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"You cannot send an email !" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
 [alert show]; 
 [alert release]; 
}

}

A: 

The MFMailComposeViewController is only available on iPhone OS > 3.0. Are you running that version your development phone?

pzearfoss
Yes - running 3.1 in Simulator and in my iPhone as well
A: 

Silly me - I found that I had conflicting calls to send the email - I was calling BOTH the mailTo:URL and the MFMailComposer methods with the same action trigger.....