Hru*_*tai 5 csv iphone mfmailcomposeviewcontroller
我已经创建了一个csv文件,我也将它附加到MFMailComposer,它显示我的邮件编写器,但当我发送给用户的电子邮件时,它没有显示我在电子邮件中附加csv文件.我已经使用此代码创建csv文件并在其中添加数据.
NSMutableString *mainString=[[NSMutableString alloc]initWithString:@""];
//NSMutableArray *section = [[NSMutableArray alloc] init];
for(int i = 0;i<[NameArray count];i++)
{
NSString *string=[indexArray objectAtIndex:i];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@"\"%@\"",string];
string=[NameArray objectAtIndex:i];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@",\"%@\"",string];
string=[typearray objectAtIndex:i];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@",\"%@\"",string];
[mainString appendFormat:@",\"%@\"",string];
[mainString appendFormat:@"\n"];
}
NSLog(@"getdatafor csv:%@",mainString);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"history.csv"];
// filePath = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData* settingsData;
settingsData = [mainString dataUsingEncoding: NSASCIIStringEncoding];
NSError *error;
[settingsData writeToFile:filePath atomically:YES];
// NSLog(@"writeok");
NSData *mediaData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMapped error:&error];
NSLog(@"Length:%d Error:%@",[mediaData length],[error localizedDescription]);
Run Code Online (Sandbox Code Playgroud)
这里上面的代码工作正常我得到[mediaData length]我从这里附加CSV文件.
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"history" ofType:@"csv"];
NSData *myData = [NSData dataWithContentsOfFile:path];
// Fill out the email body text
NSString *emailBody = @"history";
[picker setMessageBody:emailBody isHTML:NO];
[picker addAttachmentData:myData mimeType:@"text/cvs" fileName:@"history"];
[self presentModalViewController:picker animated:YES];
[picker release];
Run Code Online (Sandbox Code Playgroud)
上面的代码也正常工作.它显示我附加的CSV文件,但当我通过电子邮件发送邮件时,接收器没有收到附加的CSV文件.这段代码有什么问题.为什么接收器没有得到附件.?
| 归档时间: |
|
| 查看次数: |
1991 次 |
| 最近记录: |