UIWebView使用Google搜索,具体取决于本地语言

时间:2014-04-25 13:38:36

标签: ios objective-c uiwebview

我正在使用UIWebView并且我已经获得UITextField获取字符串,我会以这种方式转换为网址

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];

我想要的是根据设备的设定语言(或任何其他方式,使用某种GPS获取位置)创建动态网址,以便在{{1我将拥有

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= comit来实现此代码

fr

提前致谢

1 个答案:

答案 0 :(得分:1)

Google可以使用hl参数指定语言,但仍会使用.com网站。

如果这适合您,请更改搜索网址,并使用设备的区域设置来设置搜索语言,如下所示:

[NSString stringWithFormat:@"http://www.google.com/search?q=%@&hl=%@", urlString, [[NSLocale preferredLanguages] objectAtIndex:0]]

如果这还不够好,您必须在区域设置及其相应的顶级域名之间创建映射,并确保Google可以在这些顶级域名上使用。请参阅here国家/地区及其顶级域名列表。