initWithContentsOfURL:error: returns (null) when it should return "São Tomé and Príncipe". I’ve tested it using text without special characters, and then it worked fine.
NSString *myURL = [NSString stringWithString:@"http://mywebsite.com/api-call.php"];
NSURL *url = [[NSURL alloc] initWithString:myURL];
NSString *strResult = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",strResult);
I guess the problem is related with the encoding, but I don’t know how to fix it.
Thanks to Iulius Caesar I found out that my document wasn’t returning data in UTF-8 encoding.
I’ve modified the php file by adding
header('Content-Type: text/html; charset=UTF-8');to the top of the code and saving it as UTF-8 formated file. Now it works!