【问题标题】:mailing attached PDF from code从代码邮寄附加的 PDF
【发布时间】:2011-06-09 17:33:37
【问题描述】:

我又来了,有点麻烦。

我想从我的应用程序发送一封附有 pdf 的电子邮件,所以我做了以下操作:

- (IBAction) sendMail:(UIButton *)sender {

    MFMailComposeViewController *controller1 = [[MFMailComposeViewController alloc] init];

    controller1.mailComposeDelegate = self;
    if ([MFMailComposeViewController canSendMail]) {
        [controller1 setSubject:@"Brochure"];
        if (sender.tag == 101) {
            NSString *filePath = [[NSBundle mainBundle] pathForResource: @"web link" ofType: @"pdf"];  
            NSData *pdfData = [NSData dataWithContentsOfURL:filePath options: error:
            [controller1 setMessageBody:@"Brochure File" isHTML:YES];
            [controller1 addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"brochure.pdf"];
        }

        [self presentModalViewController:controller1 animated:YES];
    }
    [controller1 release];
}

没有问题,没有错误,没有什么。当我尝试从我的 iPad 发送它时,有一个带有“附加”文件的小图标,但是当我收到电子邮件时它是空的,没有附件,什么都没有。有什么我想念的吗?

【问题讨论】:

    标签: ios pdf attachment mailing


    【解决方案1】:

    这行代码绝对不应该编译:

    NSData *pdfData = [NSData dataWithContentsOfURL:filePath options: error:
    

    此外,您的filePath 很可能是错误的。如果 pdf 正确加载为附件,您应该看到附件的图标。相反,您会看到 pdf 本身的大图像。

    如果您在NSData *pdfData = 之后设置断点并将鼠标悬停在 pdfData 上,它可能会显示它为 nil,数据为 0 字节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2012-12-25
      • 2019-04-19
      • 1970-01-01
      • 2012-04-18
      • 2022-08-21
      相关资源
      最近更新 更多