我正在尝试将电子邮件作为附件添加到我的邮件中。我就是这样做的。
-(IBAction)mailPDF:(id)sender{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSLog(@"myData is %@",myData);
[controller setSubject:@"Geselecteerde favorieten van Genk on Stage"];
[controller setMessageBody:@"<p>Hallo muziekliefhebber <br /> In bijlage vind je jouw favorieten. Volg en praat met ons mee op facebook.com/genkonstage of @genkonstage!<br /> Veel plezier op Genk on stage! </p>" isHTML:YES];
if (controller){
[self presentModalViewController:controller animated:YES];
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
}else{
NSLog(@"nothing to show");
}
}
这就是我设置 myData 的方式
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"favorite.pdf"];
myData = [NSData dataWithContentsOfFile: filePath];
当我查看我的日志myData
(这是我的pdf)时,它不是空的。另外,当我在查找器中浏览到模拟器的文档文件夹时,我看到我有一个 PDF。
有人可以告诉我为什么我的 pdf 没有添加到我的邮件中吗?
谢谢!
编辑 看来上面的代码只适用于IOS6。所以现在的问题是。为什么它在 IOS 5 中不起作用
最佳答案
您首先呈现 View Controller ,然后附加文件。更改操作顺序:
也就是说,在您的代码行中:
[self presentModalViewController:controller animated:YES];
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
将它们修改为:
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
[self presentModalViewController:controller animated:YES];
希望能解决这个问题:)
关于iphone - pdf 未添加到 IOS 5 中 Objective-C 中的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17087001/