1
votes

In my app, I generate a UTF8-encoded CSV file with CHCSVWriter and display it using QLPreviewController. The file may have some special characters, such as umlauts (ü, ä), and I have checked the files and they are being generated properly. However when they are displayed with QLPreviewController, the characters are screwed up! I have checked my encodings throughout, and they are all UTF-8, so the code points are not being corrupted. Is there a problem with QLPreviewController? Any suggestions?

Here is the code I am using to create and display the CSV file:

NSString *path = @"my path";

CHCSVWriter *csvWriter = [[CHCSVWriter alloc] initWithCSVFile:path atomic:NO];
csvWriter.encoding = NSUTF8StringEncoding;
NSDictionary* w;
for (w in items) {
    [csvWriter writeField:[w valueForKey:@"a"]];
    [csvWriter writeField:[w valueForKey:@"b"]];
    [csvWriter writeLine];
}
[csvWriter closeFile];
[csvWriter release];

QLPreviewController *ql = [[QLPreviewController alloc] init];
[ql setDataSource:self];
[self presentModalViewController:ql animated:YES];
[ql release];

And here is what is being displayed:

enter image description here

3
hi! I'm having the same problem. Any solution??Frade

3 Answers

1
votes

Ive have this problem also and I think it is a bug in the QLPReviewController. I filed a bug with Apple but haven't seen any resolution yet.

1
votes

I also have this problem when viewing utf-8 html files.

I solved it by setting <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> in the header.

UTF-16 or Latin1 worked fine without the encoding header, so if you ex. encode your file in UTF-16 it should work.

0
votes

Got it..

try changing data encoding

csvWriter.encoding = NSUTF16BigEndianStringEncoding;

it worked for me..