我在 xcode 中编写了一个小脚本,它在我的应用程序中获取一个 CSV 文件并将其作为附件发送。当我单击电子邮件按钮时,一切正常(即主题、正文等)。它也显示 CSV 文件,但是当我检查我的电子邮件时,我看到了除 csv 文件之外的所有内容。我难住了。这是我使用的代码。我也试过 filename:@"isitlist.csv。csv 文件位于我的主文件夹中。
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Guest List Form"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
[mailer setToRecipients:toRecipients];
[mailer addAttachmentData:[NSData dataWithContentsOfFile:@"isit_list.csv"]
mimeType:@"text/csv"
fileName:@"isit_list"];
[self presentModalViewController:mailer animated:YES];
NSString *emailBody = @"Please fill out the attached file and then email it back to us. Also, please attach some photos to use for the slideshow. We suggest no more than 10.";
[mailer setMessageBody:emailBody isHTML:NO];
// only for iPad
// mailer.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mailer animated:YES];
[mailer release];