0

我又来了,有点麻烦。

我想从我的应用程序发送一封附有 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 发送它时,有一个带有“附加”文件的小图标,但是当我收到电子邮件时,它是空的,没有附件,什么也没有。有什么我想念的吗?

4

1 回答 1

0

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

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

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

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

于 2011-07-12T23:02:44.693 回答