无法使用电子邮件xcode发送pdf文件

时间:2011-10-19 03:26:54

标签: iphone

请帮帮我!尽管我在电子邮件中看到图标文件附件,但我可以发送图像但不能发送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];

帮助我........

谢谢!

1 个答案:

答案 0 :(得分:3)

使用

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

而不是

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

此外,数据可以是NSData,而不是NSMutableData

NSData *data = [NSData dataWithContentsOfFile:file];

最后,您确定PDF文件出现在您所指的路径上吗?变量数据有效吗?

相关问题