在MFMailComposeViewController中显示pdf文档

时间:2013-04-24 21:23:23

标签: ios objective-c pdf mfmailcomposeviewcontroller

我读过帖子说`MFMailComposeViewController应该显示附加的PDF文件,如果是1页文档,但由于某种原因,我的PDF总是显示为一个图标。我希望它显示PDF,因为它只有1页。 PDF似乎很好,因为我可以发送电子邮件,我可以在邮件应用程序或我的计算机上打开它。

iOS 6.0或更高版本默认情况下是否未启用此功能,或者是否缺少某些内容?

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

// create the message body.
NSMutableString *body = [[NSMutableString alloc] init];

// add the user name to the email body.
[body appendFormat:@"Name: %@", userName];

// add the pdf to the email.
NSData *data = [NSData dataWithContentsOfFile:path];
[controller addAttachmentData:data mimeType:@"application/pdf" 
                                   fileName:@"test.pdf" 
                           includeExtension:YES]];

// add the body string to the email body.
[controller setMessageBody:body isHTML:NO];

// show the email controller.
[self presentViewController:controller animated:YES completion:nil];

0 个答案:

没有答案