Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting wrong country code from phone number #54

Closed
ignotusverum opened this issue Jun 29, 2016 · 2 comments
Closed

Detecting wrong country code from phone number #54

ignotusverum opened this issue Jun 29, 2016 · 2 comments

Comments

@ignotusverum
Copy link

ignotusverum commented Jun 29, 2016

Code example:

let numberPhone = try PhoneNumber(rawNumber: "(636) 275-4512")

let countryCodeNumber = numberPhone.countryCode

let phoneNumberKit = PhoneNumberKit()
var countryCode = phoneNumberKit.countriesForCode(countryCodeNumber)?.first

log:
countryCodeNumber = 1

countryCode = "AG" // Should be US

@ignotusverum ignotusverum changed the title Detecting wrong country code Detecting wrong country code from phone number Jun 29, 2016
@marmelroy
Copy link
Owner

marmelroy commented Jun 29, 2016

Hi @redcirclegame!

Thanks for this. The issue here is that you don't get the main country for a dialing code by asking for the first country in the array.

There is a specific function for this:

let countryCode = PhoneNumberKit().mainCountryForCode(countryCodeNumber)

returns US

@ignotusverum
Copy link
Author

Oh, i see, thanks for such quick response @marmelroy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants