Tuesday, July 31, 2012

MFMailComposeViewController send pdf file

Direct pdf file send to MFmailcomposer:--

NSString *filePath = [[NSBundle mainBundle] pathForResource: @"file" ofType: @"pdf"];
    NSData *pdfData = [NSData dataWithContentsOfFile: filePath];
    [mailController addAttachmentData: pdfData mimeType:@"application/pdf" fileName:@"file.pdf"]


NSData for pdf file send to MFmailcomposer:--





MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
        mailController.mailComposeDelegate = self;

        [mailController setSubject:@"Subject"];

        [mailController addAttachmentData:pdfData
                                 mimeType:@"application/pdf"
                                 fileName:@"file.pdf"];

        [mailController setMessageBody:@"Body" isHTML:NO];
        [self presentModalViewController:mailController animated:YES];
        [mailController release];





Attach a CSV file to a MFMailComposeViewController:--



MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"CSV File"];        
    [mailer addAttachmentData:[NSData dataWithContentsOfFile:@"PathToFile.csv"]
                     mimeType:@"text/csv" 
                     fileName:@"FileName.csv"];
    [self presentModalViewController:mailer animated:YES];

MFMailComposer sending attached image size increased:==
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
if (picker !=nil) { 
   picker.mailComposeDelegate = self; 
   NSString *msgTitle;
   [picker setToRecipients:[NSArray arrayWithObjects:@"", nil]]; 
   [picker setSubject:msgTitle];    
   [picker addAttachmentData:UIImageJPEGRepresentation(imageView.image,0.5) mimeType:@"image/png" fileName:@"img"]; 
   [self presentModalViewController:picker animated:YES];
 
NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality)

//Replace this snippet to your code
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
if (picker !=nil) { 
   picker.mailComposeDelegate = self; 
   NSString *msgTitle;
   [picker setToRecipients:[NSArray arrayWithObjects:@"", nil]]; 
   [picker setSubject:msgTitle];    
   [picker addAttachmentData:UIImageJPEGRepresentation(imageView.image,0.5) mimeType:@"image/png" fileName:@"img"]; 
   [self presentModalViewController:picker animated:YES];

No comments:

Post a Comment