我正在使用 UIWebView
并且我有一个 UITextField
获取我正在以这种方式在 URL 中转换的字符串
NSString *composedUrlString = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",urlString];
NSURL *url = [NSURL URLWithString:composedUrlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
我想要的是根据设备的设置语言创建动态 URL(或任何其他方式,不使用某种 GPS 来获取位置),以便在 composedUrlString
我会有
http://www.google.com/search?q=
http://www.google.it/search?q=
http://www.google.fr/search?q=
http://www.google.de/search?q=
视国家而定。其实我问的是是否有办法让不同的 com
, it
, fr
来实现这段代码
NSString *composedUrlString = [NSString stringWithFormat:@"http://www.google.%@/search?q=%@",localLanguage, urlString];
提前致谢
最佳答案
Google 可以使用 hl
参数来指定语言,但它仍将使用 .com 网站。
如果这对您有效,请更改搜索 URL,并使用设备的区域设置来设置搜索语言,如下所示:
[NSString stringWithFormat:@"http://www.google.com/search?q=%@&hl=%@", urlString, [[NSLocale preferredLanguages] objectAtIndex:0]]
如果这还不够好,您将必须在语言环境与其对应的 TLD 之间创建一个映射,并确保 Google 在这些 TLD 上可用。参见 here国家及其 TLD 域的列表。
关于ios - UIWebView 根据本地语言使用 Google 进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294810/