1

我有一台 iPad,它具有创建 pdf 并作为电子邮件附件发送的例程。这一切似乎都与电子邮件编辑器打开显示附加的 pdf 文档一起工作。但是,在 iPad 上进行测试时,收到电子邮件时没有附件。有任何想法吗?

    [mailComposer addAttachmentData:data mimeType:@"application/pdf" fileName:@"pdffile.pdf"];
    [self presentViewController:mailComposer animated:YES completion:nil];

非常感谢

细节:

pdf 文件被创建并称为 pdffile.pdf。以下是完整的电子邮件例程:

    MFMailComposeViewController *mailComposer;
    mailComposer  = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;
    [mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
    [mailComposer setSubject:[NSString stringWithFormat: @"i-observe Lesson Observation for: %s", "date"]];
    [mailComposer setMessageBody:[NSString stringWithFormat: @"i-observe Lesson Observation for: %s", "name"] isHTML:NO];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *file = [documentsDirectory stringByAppendingFormat:@"pdffile.pdf"];
    NSMutableData *data=[NSMutableData dataWithContentsOfFile:file];
    [mailComposer addAttachmentData:data mimeType:@"application/pdf" fileName:@"pdffile.pdf"];
    [self presentViewController:mailComposer animated:YES completion:nil];
4

3 回答 3

2

试试这个方法:

 if([MFMailComposeViewController canSendMail]){      

        MFMailComposeViewController *mail=[[MFMailComposeViewController alloc]init];
        mail.mailComposeDelegate=self;
        [mail setSubject:@"Email with attached pdf"];   
        NSString *newFilePath = @"get path where the pdf reside";

        NSData * pdfData = [NSData dataWithContentsOfFile:newFilePath];
    [mail addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"yourpdfname.pdf"];
        NSString * body = @"";
        [mail setMessageBody:body isHTML:NO];
        [self presentModalViewController:mail animated:YES];
        [mail release];         
    }
    else
    {
        NSLog(@"Message cannot be sent");
    }
于 2013-01-19T01:23:41.530 回答
0

下一个解决方案基于假设 pdf 文件位于您的主包中:

 NSBundle *mainBundle = [NSBundle mainBundle];
        NSString *myFile = [mainBundle pathForResource: @"RealNameofFile" ofType: @"pdf"];
        NSData *pdfD = [NSData dataWithContentsOfFile:myFile];
        [mailViewController addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"Nametodisplayattached.pdf"];
于 2013-08-07T14:31:58.367 回答
0

确保文件与表格单元格同名

于 2014-01-09T23:58:07.607 回答