How to open cyrillic domain in UIWebView?

假如想象 提交于 2019-12-20 04:54:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!