我正在尝试在iPad上发送带有.csv附件的电子邮件。我按照给出的许多示例使用MFMailComposer,如下所示。发送电子邮件时,我可以在MFMailComposer窗口中看到正确的文件附件,但是当我收到电子邮件时,没有附加任何内容。任何有关我可能做错的指导都将不胜感激。谢谢你的时间,
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[NSString stringWithFormat:@"Results for Participant %d.", [delegate participantNumber]]];
[mailViewController setMessageBody:[NSString stringWithFormat:@"The results for Participant %d in Study: %@ are as follows:", [delegate participantNumber], [[delegate getAccountData:([delegate accountItems] * [delegate accountNumberInUse])] description]] isHTML:NO];
NSData *textData = [[NSData alloc] initWithContentsOfFile:dataFileName];
[mailViewController addAttachmentData:textData mimeType:@"text/csv" fileName:[NSString stringWithFormat:@"Participant_Info_#%d.csv", [delegate participantNumber]]];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
答案 0 :(得分:0)
检查textData变量的内容,同样(只是从你的代码中猜测)dataFileName需要包含文件的完整系统路径,而不仅仅是它的名字!
NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:dataFileName ofType:nil];