Iphone – MFMailComposer – works in simulator but not in iPhone 2G

iphone

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]; 
}

}

Best Answer

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

Related Topic