I am doing a app for Ipad,I am trying to attached a pdf file to send by email ,for this I create a pdf like this.
pageSize= CGSizeMake(612, 792);
NSString *fileName=@"prueba.pdf";
NSArray *paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName= [documentsDirectory stringByAppendingPathComponent:fileName];
NSString *url=[fileName stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName];
NSData *pdfData = [NSData dataWithContentsOfFile:url];
the next step is create a email to send the pdf I dis this, like this..
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"esto es para probar"];
NSArray *toRecipients = [NSArray arrayWithObjects:currentuser.email, nil];
[mailer setToRecipients:toRecipients];
[mailer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fileName];
NSString *emailBody = @"correo prueba";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
mailer.modalPresentationStyle = UIModalPresentationPageSheet;
}else{
...
I generate I create the pdf and everything is right, when I see the email I see de pdf attached like a image (picture), but the problem is that when I receive the email nothing is attached.
any idea
It seems to me that in your code you are reversing the order of the two following steps:
If I interpret correctly the meaning of
generatePdfWithFilePath:pdfFileName
, I assume this step should be executed before the other. I.e.:Hope this helps.
Finally work, I put the solution for someone.. thanks
ok I explain better, sorry, before to fix it up I have this, the problem was in this line
my url was prueba.pdf/prueba.pdf so the path was wrong!!
I fix it up like this
and erase the *url I don't use it.