我正在使用下面的代码csv
通过电子邮件发送。电子邮件已发送,我在收件箱中收到了,但我没有收到csv
附加文件,知道出了什么问题吗?
-(void)generateCSV
{
NSFileManager *filemgr = [NSFileManager defaultManager];
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
if ([filemgr fileExistsAtPath:[NSString stringWithFormat:@"%@/test.csv", docsDir] ] == NO)
{
[filemgr createFileAtPath:[NSString stringWithFormat:@"%@/test.csv", docsDir] contents:[@"" dataUsingEncoding: NSUnicodeStringEncoding] attributes: nil];
}
surveyarray = [db retrieveSurvey];
CHCSVWriter * csvWriter = [[CHCSVWriter alloc] initWithCSVFile:[NSString stringWithFormat:@"%@/test.csv", docsDir] atomic:NO];
NSString *str = [NSString stringWithFormat: @"No, CreatedDate, Question1, Question2, Question3, Comment\n"];
[csvWriter writeField:str];
for(int i = 0; i < surveyarray.count; i++)
{
survey = [surveyarray objectAtIndex:i];
NSString *str = [NSString stringWithFormat: @"%d, %@, %@, %@, %@, %@\n", i, survey.createddate, survey.question1, survey.question2, survey.question3, survey.comment];
[csvWriter writeField:str];
}
NSMutableString *subject = [[NSMutableString alloc] init];
NSMutableString *emailBody = [[NSMutableString alloc] init];
[subject appendString:@""];
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:subject];
NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
[mailer setToRecipients:toRecipients];
NSData *myData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/test.csv", docsDir]];
NSLog(@"%@", myData);
[mailer addAttachmentData:myData mimeType:@"text/csv" fileName:@"test.csv"];
[mailer setMessageBody:emailBody isHTML:NO];
mailer.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mailer animated:YES];
[mailer release];
[subject release];
[emailBody release];
[csvWriter release];
}
我正在生成csv
文件,然后将电子邮件作为附件发送。
我打开邮箱中的电子邮件,它不包含任何附件。