-1

I have an iPad application, composed of a root view controller that loads a second view controller. Within that second view controller, I have one button that should present an MFMailComposeViewController.

My Problem is:
On the Simulator, this works fine. However, on actual device, pressing this button locks up the screen and seems to disable all user interaction with the interface.

My Code is:

//************** Send Email using Default IM ************************
-(void) showEmailModalView
{
    NSLog(@"Start method <ExportStatisticsController> : <showEmailModalView>  --");


    //    emailTextField.text = [emailTextField.text stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
    //    subjectTextField.text = [subjectTextField.text stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
    //    messageBodyTextView.text = [messageBodyTextView.text stringByReplacingOccurrencesOfString:@"(null)" withString:@""];

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self; // &lt;- very important step if you want feedbacks on what the 
    //user did with your email sheet

    [picker setSubject:@""];

    NSArray *torec=[[NSArray alloc] initWithObjects:@"xyz@company.com", nil];
    [picker setToRecipients:torec];
    [torec release];

//------ message body ---

    NSString *body =@"";

    [picker setMessageBody:body isHTML:NO]; // depends. Mostly YES, unless you want to send it as plain text (boring)

    picker.navigationBar.barStyle = UIBarStyleBlack; // choose your style, unfortunately, Translucent colors behave quirky.
//    picker.ModalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentModalViewController:picker animated:YES];
    [picker release];
    NSLog(@"End method <ExportStatisticsController> : <showEmailModalView>  --");

}

What could I be doing wrong to cause a screen freeze like this?

MKJParekh
  • 34,073
  • 11
  • 87
  • 98
Play cool
  • 158
  • 4
  • 12

1 Answers1

0

The device is probably not set up to send mail.

Before using the MFMailComposeViewController you should call [MFMailComposeViewController canSendMail] to ensure that the device is configured to send mail.

It's probably a good idea too to check that your picker variable is non-nil before trying to present it as a modal view controller.

idz
  • 12,825
  • 1
  • 29
  • 40