我正在CSV
使用 CoreData 创建一个文件,CHCSVWriter
到目前为止一切顺利,并且文件正在完美创建。我的问题是当我尝试发送CSV
我创建的文件时,我正在运行一些问题,我CSV
用 Excel 打开文件,而不是希伯来文文本,我看到的是乱码。
在使用NSLog
打印CSV
字符串的结果时,我看到希伯来语就好了。即使在它来回NSString
转换之后。NSData
这就是我得到的:
יוסי צפר
这是我的代码:
- (void)createCSV
{
CHCSVWriter *writer = [[CHCSVWriter alloc] initForWritingToCSVFile:[self csvFilePath]];
for (EWDBUsers *user in self.users)
{
[writer writeField:user.name];
[writer writeField:user.company];
[writer writeField:user.email];
[writer writeField:user.telephone];
[writer finishLine];
}
[writer closeStream];
}
- (NSString*)csvFilePath
{
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = @"users.csv";
return [documentsDirectory stringByAppendingPathComponent:filename];
}
- (void)showMailComposerController
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"Users List"];
[controller setMessageBody:@"Attachment." isHTML:NO];
NSError *error;
NSString *csvFileString = [NSString stringWithContentsOfFile:[self csvFilePath] encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@", csvFileString);
NSData *csv = [csvFileString dataUsingEncoding:[NSString defaultCStringEncoding]];
[controller addAttachmentData:csv mimeType:@"text/cvs" fileName:@"users.csv"];
if (controller) {
[self presentModalViewController:controller animated:YES];
}
} else {
return;
}
}
有人可以告诉我我做错了什么吗?
提前致谢。