iphone - pdf 未添加到 IOS 5 中 Objective-C 中的电子邮件

标签 iphone ios objective-c mfmailcomposeviewcontroller

我正在尝试将电子邮件作为附件添加到我的邮件中。我就是这样做的。

-(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/

相关文章:

ios - 检测哪个 viewController 呈现了 SideMenu 并为其呈现实现适当的功能

iphone - 如何在tableview中使用uialert和uiactionsheet

objective-c - present Modal ViewController 给出黑屏

iphone - 如何将图像放入 iPad 上的 UIImagePickerController

iphone - 为什么 iphone 翻过来时文字会变大?

ios - 滚动出现在我的 PageScroll 上。如何禁用它?

ios - UItableView布局错误

iphone - 如何从 Web 应用程序加载 iPhone 应用程序

iphone - AVAudioRecorder 如何在 iphone 中获得麦克风电平?

objective-c - 使用什么对象进行特殊文本编辑