这是我的代码:
NSArray *recipient = [NSArray arrayWithObjects:@"testemail@office.co.uk",nil];
NSString *fileName = @"SurveyResults.txt";
NSString *homeDir = NSHomeDirectory();
NSString *fullPath = [homeDir stringByAppendingPathComponent:fileName];
[super viewDidLoad];
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[NSString stringWithFormat:@"Place Holder Subject"]];
[mailViewController setMessageBody:@"See Attached" isHTML:NO];
[mailViewController setToRecipients:recipient];
[mailViewController addAttachmentData:[NSData dataWithContentsOfFile:fullPath] mimeType:@"text/txt" fileName:fileName];
[self presentModalViewController:mailViewController animated:YES];
} else
NSLog(@"Device cannot send email at this time. Please check you are connected to the internet and try again");
问题是,当 MailComposer 启动时,它在“查看附件”下有一个小 txt 文件图像,下面有一个名为 SurveyResults 的名称,但是,当我实际发送电子邮件时,txt 文件没有附加,有人可以解释一下吗?