I have a Mac Os App that retrieve the html code of a web page and put it in a NSString. The code is:
NSString*linkURL=[NSString stringWithFormat:@"https://www.example.com"];
NSURL *targetURL=[NSURL URLWithString:linkURL];
NSData *htmlData = [NSData dataWithContentsOfURL:targetURL];
NSString *dataString=[[NSString alloc]initWithData:htmlData encoding:NSUTF8StringEncoding];
This app runs on Mac OsX 10.8 and works fine.
After system update to Mac OsX 10.12 I have a problem with the NSUTF8StringEncoding
.
The NSString *dataString
contains only a part of the html code and not the entire html code.
I verified that htmlData
contains the right code because I write htmlData
to a txt file and it contains all the html code that I retrieved.
But when I initialize the NSString
with the htmlData
using NSUTF8StringEncoding the string contains only the first part of the html code.
I tried also:
NSString *dataString=[[NSString alloc]initWithUTF8String:[tutorialsHtmlData bytes]];
with the same result.
Also the code:
NSString *dataString=[NSString stringWithContentsOfURL:targetURL encoding:NSUTF8StringEncoding error:nil];
gave me the same result.
The html code of the web page is UTF-8 coded, this is its meta:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Anyone can help me? Thanks