How to use MFMailComposeViewController

1.1k Views Asked by At

I am using MFMailComposeViewController in my app and the mail sending part seems to be OK. But when I leave the mail app, things go wrong :

- one toolbar (UIToolbar object) has disappeared.
- one pointer (UIImageView*) has become nil, without me doing anything for that to happen.

In other words the calling environment is changed although I do not want it to change. Where could be my mistake?

Here is my code, in case someone can see something wrong :

- (void)mailComposeController:(MFMailComposeViewController*)controller  
      didFinishWithResult:(MFMailComposeResult)result 
                    error:(NSError*)error
{
[controller dismissModalViewControllerAnimated:YES];
}


-(IBAction)sendAsEMail {
MFMailComposeViewController *mailComposeViewController=[[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate=self;
[mailComposeViewController setSubject:@"Mail subject"];
[mailComposeViewController setMessageBody:@"This is for you !" isHTML:NO]; 
[mailComposeViewController addAttachmentData:
 [NSData dataWithContentsOfFile:[[My_ViewController getDocDir] stringByAppendingPathComponent:
                                 [pictureNames objectAtIndex:userItemSelected]]]
                                    mimeType:@"image/png" fileName:@"Picture.png"];
if (mailComposeViewController) [self presentModalViewController:mailComposeViewController animated:YES];
[mailComposeViewController release];
}

Thanks for any piece of relevant information.

1

There are 1 best solutions below

0
On

Try out this link it explain in detail

  1. Add framework
  2. Then .h file header files
  3. Then .m file the mail code

Check at this link.