I\'m getting an html file as NSData and need to parse it to extract some info. My approach was to convert it to NSString with UTF8 encoding (the html has non english characters,
I'm responding to the Martijn Thé thread above, here, as I couldn't put a readable code snippet in the comments.
I found that if on the server , the response content type is set to 'text/plain', then (__bridge CFStringRef) [response textEncodingName] will be null, and if you try to pass this to CFStringConvertIANACharSetNameToEncoding you will get an EXC_BAD_ACCESS signal.
If the content type of the response is set to 'text/html; charset=utf-8', then everything works as expected. To handle the 'text/plain' content type, this is what I did:
CFStringRef sRef = (__bridge CFStringRef)[response textEncodingName];
if (sRef)
{
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding(sRef);
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
}
else
{
encoding = NSASCIIStringEncoding;
}