我试图将我的pdf附加到应用内邮件中。应用程序内邮件显示带有pdf的图标,但不会发送它。我不知道为什么......
以下是代码:
- (void)openInEmail {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
viewController.mailComposeDelegate = self;
[viewController setSubject:@"Stundenplan 1A"];
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/Stundenplan_1A.pdf", docDirectory];
NSMutableData *data=[NSMutableData dataWithContentsOfFile:filePath];
[viewController addAttachmentData:data mimeType:@"text/pdf" fileName:@"Stundenplan_1A.pdf"];
[self presentModalViewController:viewController animated:YES]; }
}
有什么想法吗?
答案 0 :(得分:0)
你试过吗?
NSString *filePath = [documentsDirectory stringByAppendingFileComponent:@"%@/Stundenplan_1A.pdf"];
而不是
NSString *filePath = [NSString stringWithFormat:@"%@/Stundenplan_1A.pdf", docDirectory];
而不是NSMutableData,您可以尝试使用NSData
NSData *data = [NSData dataWithContentsOfFile:file];
答案 1 :(得分:0)
像这样更改mime类型。
NSURL *url = [NSURL URLWithString:pdfURL];
NSData *pdfData = [NSData dataWithContentsOfURL:url];
[mailComposeView addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"CheckList.pdf"];