ios WhatsApp 如何知道我联系人的国家/地区代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13052728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:56:08  来源:igfitidea点击:

How does WhatsApp know the country code of my contacts?

iphoneobjective-ciostimezone

提问by Snowman

I'm in the US, where a phone number looks like this:

我在美国,那里的电话号码是这样的:

without country code: 123-456-7890

with country code: +1 123-456-7890

没有国家代码:123-456-7890

国家代码:+1 123-456-7890

Now, according to Wikipedia, a phone number in Italy has this format:

现在,根据维基百科,意大利的电话号码格式如下:

347 xxxxxxx (from within Italy)

347 xxxxxxx(来自意大利境内)

So that could look like a US number: 347-123-4567

所以它看起来像一个美国号码:347-123-4567

When I open all my contacts on WhatsApp, it automatically adds the country code, so if I have a US phone 123-456-7890, it adds a +1. But how does it know it's a US number? It could have been anything.

当我在 WhatsApp 上打开所有联系人时,它会自动添加国家/地区代码,因此如果我有美国电话 123-456-7890,它会添加 +1。但是它怎么知道这是一个美国号码呢?它可以是任何东西。

I guessed that it uses my current locale or timezone to determine where I am, and any phone numbers that don't have a country code, just add the current user's country code. But I changed my locale settings in my iPhone and it was still able to guess which country the number belongs to.

我猜它使用我当前的语言环境或时区来确定我在哪里,以及任何没有国家代码的电话号码,只需添加当前用户的国家代码。但是我在 iPhone 中更改了语言环境设置,它仍然能够猜测该号码属于哪个国家/地区。

Any idea how that's possible?

知道这怎么可能吗?

Update: Also, I just tried adding a new phone number while my phone was in airplane mode while my region settings were set to Italian while my timezone was set to Rome, Italy, and it still knew I put a US number, so it can't possibly be connecting to a server to get this info.

更新:另外,我只是尝试在我的手机处于飞行模式时添加一个新电话号码,而我的地区设置设置为意大利语,而我的时区设置为意大利罗马,它仍然知道我输入了美国号码,因此它可以'不可能连接到服务器来获取此信息。

采纳答案by Michael Donohue

WhatsApp knows what country code you are 'in' because you have verified your own phone number with WhatsApp. Phone numbers that don't have an explicit international format, meaning they don't start with '+' or '00', are checked against your own verified country code. This is how WhatsApp knows to use country code 1 in your case.

WhatsApp 知道您所在的国家/地区代码,因为您已使用 WhatsApp 验证了您自己的电话号码。没有明确的国际格式的电话号码,这意味着它们不以“+”或“00”开头,会根据您自己验证的国家/地区代码进行检查。这就是 WhatsApp 知道在您的情况下使用国家/地区代码 1 的方式。

回答by rmaddy

Phone numbers without an explicit country code are assumed to be local to your own country. Your own country is determined by the Region Format setting (Settings, General, International).

没有明确国家/地区代码的电话号码被假定为您所在国家/地区的本地电话号码。您所在的国家/地区由区域格式设置(设置、常规、国际)决定。

So when you enter a number like (347) 123-4567this is assumed to be a US phone number because you have chosen United States under the Region Format. So WhatsApp can assume the +1 because there is no explicit country code in the number.

因此,当您输入诸如(347) 123-4567 之类的数字时,它被假定为美国电话号码,因为您在区域格式下选择了美国。因此 WhatsApp 可以假设 +1,因为号码中没有明确的国家/地区代码。

Lets say you have a friend in Italy. The country code for Italy is +39. So in Contacts you would enter their number as +39 347 1234567.

假设您在意大利有一个朋友。意大利的国家代码是 +39。因此,在联系人中,您可以输入他们的号码+39 347 1234567

A user in Italy would enter that number simply as 347 1234567. WhatsApp would see the user's Region Format as being Italy and would know to show the +39.

意大利的用户只需输入该号码347 1234567。WhatsApp 会将用户的区域格式视为意大利,并且会知道显示 +39。