在iPhone应用程序中输入丹麦语言设置的位置时,Google API会发生错误 [英] Google API gives error when location entering in Danish language setting in iPhone Application

查看:132
本文介绍了在iPhone应用程序中输入丹麦语言设置的位置时,Google API会发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google API从地址位置查找纬度经度。它的英文语言环境工作得很好。但是,在国际化中选择丹麦语设置时,它会给出Google中的服务器错误。正如我认为可能需要在应用程序中进行本地化,但如何?

解决方案

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



NSURL 对于带有特殊内容的非转义字符串(例如UTF)而言很糟糕。首先我要做的是检查 NSURL 你是否回到 nil



执行 NSURL 字符串的方法是在传入字符串之前使用 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]]);

带输出

 带字符串的网址! (null)
带有转义字符串的网址! http://test.com/test%C3%A5%C3%A4%C3%B6test


I am using a Google API to finding latitude longitude from Address location. And its working fine in English language settings. But when select Danish setting in Internationalization then it gives a server error from "Google". As I think there may be required to do localization in app but how?

解决方案

Muhammad is giving the answer above, but I'll take the opportunity to explain what (I think) the issue is as well, as I had this issue in live production code a few weeks ago.

NSURL is flat out bad with unescaped strings with "special" content (e.g. UTF). First thing I'd do is check if the NSURL you get back is nil.

The way to do NSURL strings is to use stringByAddingPercentEscapesUsingEncoding before passing the string in.

This simple example demonstrates this:

NSString *string = @"http://test.com/teståäötest";

NSLog(@"url with string! %@", [NSURL URLWithString:string]);
NSLog(@"url with escaped string! %@", [NSURL URLWithString:
  [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]);

with output

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

这篇关于在iPhone应用程序中输入丹麦语言设置的位置时,Google API会发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆