问题
I try to open cyrillic url in UIWebView, but it's can open. I use the following code%
urlString = [NSString stringWithFormat:@"http://%@", urlString];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
If i try to open https://www.google.ru/webhp?q=президент#newwindow=1&q=президент everything is OK, but when I try to open президент.рф it's doesn't work. What I need to do for open cyrillic domain?
回答1:
To connect to IDN (international domain name) URLs, you need to encode them in Punycode. For example, this URL would be encoded as http://xn--d1abbgf6aiiy.xn--p1ai.
Unfortunately I don't know of any built-in punycode support in iOS. But there are third-party tools like NSURL-IDN (which is extracted from the OmniNetworking library).
来源:https://stackoverflow.com/questions/28835013/how-to-open-cyrillic-domain-in-uiwebview