libPhoneNumber-iOS icon indicating copy to clipboard operation
libPhoneNumber-iOS copied to clipboard

Problem getting correct country code

Open varali opened this issue 3 years ago • 0 comments

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"
}

varali avatar Apr 27 '22 17:04 varali