eXit_door 2013-06-14 03:05 采纳率: 0%
浏览 2212
已采纳

IOS5中pdf添加到Email中

添加一个pdf到Email中,操作如下:

-(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");
    }
}

设置数据:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"favorite.pdf"];
 myData = [NSData dataWithContentsOfFile: filePath];

在看log mydata(就是pdf)时,显示并不为空。浏览模拟器“我的文档”也能看见pdf。
请指教为什么我的pdf无法添加到Email中?

在ios6中没问题,只有在ios5中有问题。

  • 写回答

1条回答

  • O_1001_O 2013-06-14 06:16
    关注

    你先显示了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];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services