2011-10-19 23 views
6

请帮助我!尽管我在电子邮件中看到图标文件附件,但我可以发送图像,但无法发送PDF文件。 我的代码:不能发送电子邮件xcode的pdf文件

MFMailComposeViewController *sendmailview = [[MFMailComposeViewController alloc] init]; 
    sendmailview.mailComposeDelegate = self; 
// I can send image with: 
// UIImage *roboPic = [UIImage imageNamed:@"Default.png"]; 
// NSData *imageData = UIImageJPEGRepresentation(roboPic, 1); 
// [sendmailview addAttachmentData:imageData mimeType:@"image/png" fileName:@"Default.png"]; 

// But Can't send pdf file 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *documentsDirectory = [paths objectAtIndex:0]; 

     NSString *file = [documentsDirectory stringByAppendingFormat:@"book.pdf"]; 

    NSMutableData *data=[NSMutableData dataWithContentsOfFile:file]; 

    [sendmailview addAttachmentData:data mimeType:@"application/pdf" fileName:@"book.pdf"]; 

// I see icon book.pdf when attach,but when i sent mail,mail receiver not see pdf file... 

     [self presentModalViewController:sendmailview animated:YES]; 

    [sendmailview release]; 

帮我........

谢谢!的

NSString *file = [documentsDirectory stringByAppendingFormat:@"book.pdf"]; 

而且

回答

4

使用

NSString *file = [documentsDirectory stringByAppendingFileComponent:@"book.pdf"]; 

相反,数据可以NSData而不是NSMutableData

NSData *data = [NSData dataWithContentsOfFile:file]; 

最后,您是否确保PDF文件存在于您所指的路径中?变量数据是否有效?

+0

谢谢!我做了:NSString * file = [documentsDirectory stringByAppendingFormat:@“/ book.pdf”]; 现在就行!谢谢你的帮助 – user1002290

相关问题