My app crash with MFMailComposeViewController and MFMessageComposeViewController when I re-launch it.

Posted by Dolwen on Stack Overflow See other posts from Stack Overflow or by Dolwen
Published on 2010-12-30T14:56:48Z Indexed on 2011/01/15 22:53 UTC
Read the original article Hit count: 204

Hello all,

I encounter a crash with MFMailComposeViewController, MFMessageComposeViewController and multitasking on IOS 4.2 (both simulator and IPHone 4).

Code i use :

 Class emailClass = (NSClassFromString(@"MFMailComposeViewController"));
 if( emailClass != nil )
 {
  MFMailComposeViewController * controller = [[emailClass alloc] init];

  if([emailClass canSendMail])
  {
   // delegate
   controller.mailComposeDelegate = self;

   // subject
   [controller setSubject:@"Hello All."];

   // main message
   [controller setMessageBody:@"I love Stackoverflow.com !" isHTML:NO];

   // adding image attachment  
   // getting path for the image we have in the tutorial project  
   NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];  

   // loading content of the image into NSData  
   NSData *imageData = [NSData dataWithContentsOfFile:path];

   // adding the attachment to he message  
   [controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"My Byook image"];

   // setting different than the default transition for the modal view controller
   [controller setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

   // show
   [[CGameStateManager getCurrentGameState] presentModalViewController:controller animated:YES];
  }

  [controller release];
 }

To close MFMailComposeViewController i use :

[[CGameStateManager getCurrentGameState] dismissModalViewControllerAnimated:NO];

Then the app crash on the "dismissModalViewControllerAnimated:" and we can read in the debugger with NSZombieEnabled : * -[UIImage isKindOfClass:]: message sent to deallocated instance 0xb0b9f80

Anyone have an answer to solve my problem ? :) Thx

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c