libphonenumber ios get country code for country

2019-09-09 16:06发布

问题:

Given a country, how do I get the countryCode? The following method is not working

NSNumber* code = [phoneUtil getCountryCodeForRegion:country];

回答1:

It is working, I used it like so:

[phoneUtil getCountryCodeForRegion:@"US"]

and the output was 1.

Note that you have to use the ISO Country Code, 2 Digit: "US", (you can find a list here).