Thursday, November 1, 2012

How to attach PDF file In e-mail

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone



MFMailComposeViewController *picker=[[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"PDF File"]; 



 NSArray *toRecipients = [NSArray    arrayWithObjects:@"abc@example.com",nil];
 NSArray *ccRecipients = [NSArray arrayWithObjects:@"def@example.com", nil]; 
 NSArray *bccRecipients = [NSArray arrayWithObject:@"ghi@example.com"];
 [picker setToRecipients:toRecipients];
 [picker setCcRecipients:ccRecipients];
 [picker setBccRecipients:bccRecipients];

 // Attach an pdf to the email


// if it is in your NSBundle Use the following two lines


NSString *path = [[NSBundle mainBundle] pathForResource:@"Attachment" ofType:@"pdf"]; NSData *myData = [NSData dataWithContentsOfFile:path]; [picker addAttachmentData:myData mimeType:@"pdf" fileName:@"Attachment.pdf"]; 


// if it is in user documents Use the following two lines of code


NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString * path = [[paths lastObject] stringByAppendingPathComponent:@"Attachment.pdf"];



// Fill out the email body text

 NSString *emailBody = @"A PDF File is attached.";
 [picker setMessageBody:emailBody isHTML:NO];
 [self presentModalViewController:picker animated:YES];
 [picker release];       // No need if you are using iOS5+





2 comments:

  1. Nice Post ..!! I really i like the way of your writing this post. You have shared a very interesting and informative post about Mobile platform .. keep Updating..!!
    iPhone App Development And Android Application Development

    ReplyDelete