10
gen
Hi all,
with these lines of code you can use Apple iOS Mail system to send an email with an attachment!
It’s so easy that i don’t know this method!
First, import MessageUI framework, after include in your header file (.h) the import to the framework:
1 | #import messageui/MessageUI.h |
and set the delegate to
1 | mfmailcomposeviewcontrollerdelegate |
Now, create a button in your view and attach mailil function!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | - (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError*)error { [self dismissModalViewControllerAnimated:YES]; } - (IBAction) mailIt { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setSubject:@"This is the subject"]; UIImage *roboPic = [UIImage imageNamed:@"anImage.jpg"]; NSData *imageData = UIImageJPEGRepresentation(roboPic, 1); [picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"anImage.jpg"]; NSString *emailBody = @"This is the email body!!"; [picker setMessageBody:emailBody isHTML:YES]; [self presentModalViewController:picker animated:YES]; [picker release]; } |
done!
Rif: albertopasca.it


