Lessons learned from eaGeier #4

Sending a PDF File

Yet again the excellent documentation at Apple provides all you need to send an email. Start by initializing a mail-composer view controller, add a subject, a text and the file you want to attach as NSData. To allow the user to set the mail recipient just provide an empty array for the recipients. Set the delegate if you want to use the delegate functionality and finally present the mail view controller.

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[mail setSubject:@"A Subject"];
[mail setMessageBody:@"A text you want to send with the PDF file." isHTML:NO];
[mail addAttachmentData:[NSData dataWithContentsOfFile:thePathToYourPDFFile] 
               mimeType:@"text/pdf" 
               fileName:fileNameOfThePDFFile];
[mail setToRecipients:[NSArray array]];
[mail setMailComposeDelegate:self];
[self presentModalViewController:mail animated:YES];
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *