title: MFMailComposeViewController crashing while dismissModalViewControllerAnimated in iOS5
body: <p>I am using MFMailComposeViewController in my conde to provide Mail functionality but after sending mail or when i want to cancel mail it will be crashing.</p>
  
  <p>below is my code:  </p>
  
  <pre><code>(IBAction)FnForPlutoSupportEmailButtonPressed:(id)sender {
  {
      if ([MFMailComposeViewController canSendMail])
      {
          MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
  
          mailer.mailComposeDelegate = self;
  
          [mailer setSubject:@"Need help from Pluto support team"];
  
          NSArray *toRecipients = [NSArray arrayWithObjects:@"support@myplu.to",nil];
          [mailer setToRecipients:toRecipients];
  
  
          NSString *emailBody = @"";
  
          [mailer setMessageBody:emailBody isHTML:NO];
  
          //mailer.modalPresentationStyle = UIModalPresentationPageSheet;
  
          [self presentModalViewController:mailer animated:YES];
  
      }
      else
      {
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                          message:@"Your device doesn't support the composer sheet"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles: nil];
          [alert show];
      }
  } }
  
      (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
  {
  // Notifies users about errors associated with the interface    
  switch (result)
      {       case MFMailComposeResultCancelled:
                          break;
                      case MFMailComposeResultSaved:
                          break;
                      case MFMailComposeResultSent:
                          break;
                      case MFMailComposeResultFailed:
                          break;
                      default:
                          break;
      } 
      [self dismissModalViewControllerAnimated:YES];
       }
  </code></pre>
  
  <p>I have read all blog post but no solution is found, <a href="http://tinymission.com/blog/blogengine.web/post/2011/10/27/iOS5-Upgrade-Nightmares.aspx" rel="nofollow">This</a> blog post is having good explaination about this but as per this i am not presenting my view controller in viewdidload or viewdidappear.</p>
  
  <p>I'm Getting EXE_BAD_ACCESS, Following is the crash log :</p>
  
  <p>**</p>
  
  <pre><code>&gt; #0  0x00000000 in ?? ()
  &gt; #1  0x01dc5aa4 in -[UIViewController _setViewAppearState:isAnimating:] ()
  &gt; #2  0x01dc5f47 in -[UIViewController __viewDidDisappear:] ()
  &gt; #3  0x01dc6039 in -[UIViewController _endAppearanceTransition:] ()
  &gt; #4  0x01dd2e7e in -[UIViewController(UIContainerViewControllerProtectedMethods) endAppearanceTransition] ()
  &gt; #5  0x01fc8de1 in -[UIWindowController transitionViewDidComplete:fromView:toView:] ()
  &gt; #6  0x01da334b in -[UITransitionView notifyDidCompleteTransition:] ()
  &gt; #7  0x01da3070 in -[UITransitionView _didCompleteTransition:] ()
  &gt; #8  0x01da531b in -[UITransitionView _transitionDidStop:finished:] ()
  &gt; #9  0x01d23fb6 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] ()
  &gt; #10 0x01d24154 in -[UIViewAnimationState animationDidStop:finished:] ()
  &gt; #11 0x0163bbce in CA::Layer::run_animation_callbacks ()
  &gt; #12 0x03664fe4 in _dispatch_client_callout ()
  &gt; #13 0x03655997 in _dispatch_main_queue_callback_4CF ()
  &gt; #14 0x012c03b5 in __CFRunLoopRun ()
  &gt; #15 0x012bf804 in CFRunLoopRunSpecific ()
  &gt; #16 0x012bf6db in CFRunLoopRunInMode ()
  &gt; #17 0x030f1913 in GSEventRunModal ()
  &gt; #18 0x030f1798 in GSEventRun ()
  &gt; #19 0x01ce82c1 in UIApplicationMain ()
  </code></pre>
  
  <p>**</p>
  
  <p>As per updated document of apple for ios 5 they mentioned :</p>
  
  <p>presentModalViewController:animated:</p>
  
  <p>Presents a modal view managed by the given view controller to the user. (Deprecated. Use <code>presentViewController:animated:completion:</code> instead.)</p>
  
  <pre><code>- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
  Parameters
  </code></pre>
  
  <p>Dismisses the view controller that was presented by the receiver. (Deprecated. Use <code>dismissViewControllerAnimated:completion:</code> instead.)</p>
  
  <pre><code>- (void)dismissModalViewControllerAnimated:(BOOL)animated
  </code></pre>
  
  <p>I had tried this also but it still crashes</p>