iziz / libPhoneNumber-iOS

iOS port from libphonenumber (Google's phone number handling library)
Apache License 2.0
2.35k stars 459 forks source link

Problem getting correct country code #367

Open varali opened 2 years ago

varali commented 2 years ago

I am having an issue getting the correct country back from getRegionCode(forCountryCode:). For the following code, I am getting "US" back when I should be getting "CA". Can someone tell me if there is an issue with the library or if my code is incorrect?

let fullPhoneNumber = "+15065552222"

guard let phoneUtil = NBPhoneNumberUtil.sharedInstance() else {
    return "error"
}

do {
    let phoneNumber = try phoneUtil.parse(fullPhoneNumber, defaultRegion: "ZZ")

    return phoneUtil.getRegionCode(forCountryCode: phoneNumber.countryCode)

} catch {
    return "error"
}