Google API在iPhone应用程序中input丹麦语言设置的位置时出错

我正在使用Google API从地址位置查找纬度经度。 而且在英文环境下工作得很好。 但是,当select国际化的丹麦设置,然后从“谷歌”给服务器错误。 正如我认为可能需要在应用程序本地化,但如何?

当语言选择为丹麦语和响应由Google API提供

穆罕默德在上面给出了答案,但是我会借此机会解释我认为的问题,因为几个星期前我在现场制作代码中遇到了这个问题。

NSURL与“特殊”内容(如UTF)的非转义string是平淡的。 我要做的第一件事就是检查你找回的NSURL是否nil

执行NSURLstring的方法是在传入string之前使用stringByAddingPercentEscapesUsingEncoding

这个简单的例子演示了这个

 NSString *string = @"http://test.com/teståäötest"; NSLog(@"url with string! %@", [NSURL URLWithString:string]); NSLog(@"url with escaped string! %@", [NSURL URLWithString: [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]); 

与输出

 url with string! (null) url with escaped string! http://test.com/test%C3%A5%C3%A4%C3%B6test 

我不知道AFNetworking,但我会做如下与苹果的NSURL。

假设你的URL是一个名为“googlapiurl”的string,你的NSURL应该启动为:

 [NSURL URLWithString:[googlapiurl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; 

希望能帮助到你。