无法在目标c中调用csv文件到邮件 [英] Unable to attatch a csv file to mail in objective c
本文介绍了无法在目标c中调用csv文件到邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码附加生成到邮件编写器的csv文件。
NSString * recipient = @tejanvm92@gmail.com
NSArray * recipients = [NSArray arrayWithObjects:recipient,nil];
MFMailComposeViewController * mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@CSV Export];
[mailViewController setToRecipients:recipients];
[mailViewController setMessageBody:@isHTML:NO];
mailViewController.navigationBar.tintColor = [UIColor blackColor];
NSData * myData = [NSData dataWithContentsOfFile:@yourFileName.csv];
[mailViewController addAttachmentData:myData
mimeType:@text / csv
fileName:@yourFileName];
[self presentModalViewController:mailViewController animated:YES];
当代码运行时..... csv文件没有正确附加到邮件。
但是当我收到邮件时,它是空的。
解决方案
[NSData dataWithContentsOfFile:@ yourFileName.csv] //它的错误方式。
请写出csv文件的完整路径
像文件目录中的csv文件一样。
then
NSString * documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSString * csvFilePath = [documentsDirectory stringByAppendingFormat:@/ yourFileName.csv];
[NSData dataWithContentsOfFile:csvFilePath];
I'm using the following code to attach a csv file that is generated to mail composer.
NSString *recipient = @"tejanvm92@gmail.com"; NSArray *recipients = [NSArray arrayWithObjects:recipient, nil]; MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; mailViewController.mailComposeDelegate = self; [mailViewController setSubject:@"CSV Export"]; [mailViewController setToRecipients:recipients]; [mailViewController setMessageBody:@"" isHTML:NO]; mailViewController.navigationBar.tintColor = [UIColor blackColor]; NSData *myData = [NSData dataWithContentsOfFile:@"yourFileName.csv"]; [mailViewController addAttachmentData:myData mimeType:@"text/csv" fileName:@"yourFileName"]; [self presentModalViewController:mailViewController animated:YES];
When the code runs.....the csv file is not attached to the mail properly.
But When I got the mail, it is empty. Could you please help me in finding the issue?
解决方案[NSData dataWithContentsOfFile:@"yourFileName.csv"]// its wrong way.
Please write full path of csv file Like if your csv file in Documents directory. then
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *csvFilePath = [documentsDirectory stringByAppendingFormat:@"/yourFileName.csv"];
after that change in your code
[NSData dataWithContentsOfFile:csvFilePath];
这篇关于无法在目标c中调用csv文件到邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文