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

[iOS] NumberParserLibphonenumber.formatted: Failed to format phone number #15

Closed
aytunch opened this issue Feb 26, 2023 · 10 comments
Closed

Comments

@aytunch
Copy link

aytunch commented Feb 26, 2023

flutter: [DEBUG] 17:51:12 NumberParserLibphonenumber.formatted: Failed to format phone number: +12124444444, isoCode null
flutter: Exception: PlatformException(1, The country code is invalid., null, null)

Hi @natintosh :)
On iOS I am getting this error. When I was using libphonenumber: I did not get any problems. Now I changed to libphonenumber_plugin because I use iOS & Android & Web.
I pinponted the problem to this:
Screenshot 2023-02-26 at 17 54 18

@natintosh
Copy link
Owner

Hi @aytunch...

Thanks for reaching out. I'll be pushing an update later today that fixes this.

@aytunch
Copy link
Author

aytunch commented Feb 27, 2023

Ogunye, it would be awesome. I have been struggling for the past 2 days since I changed plugins. Would you be so kind to notify this post so I can give it a try? Thanks

@natintosh
Copy link
Owner

It's up now

@aytunch
Copy link
Author

aytunch commented Feb 27, 2023

Thanks for the quick fix @natintosh
But I still get an exception at the exact same place
Debugger throws an exception and never enters line 36
Edit: phoneNumber: +12124444444
isoCode: EN
Screenshot 2023-02-27 at 18 11 48

@natintosh
Copy link
Owner

natintosh commented Feb 27, 2023

Hi @aytunch

I reviewed what you sent and I observed that there was a mistake with how you are young the package

So apparently EN is not a country iso code but a country language iso code.

Screenshot 2023-02-27 at 18 26 45

Screenshot 2023-02-27 at 18 23 47

Screenshot 2023-02-27 at 18 26 23

You can view the list here for a list of country iso-codes. Then, if you don't have access to the country iso code you can pass in an empty string.

EDIT:
But this is an edge case I didn't consider. I'll try to work on a fix as soon as I can

EDIT2:
You can run getAllCountries() that returns a list of country iso codes a new property I added in this release to check for supported countries. With this you can do a check to see if that iso code is supported if not just pass an empty string

Cheers...

@aytunch
Copy link
Author

aytunch commented Feb 27, 2023

Thank you for the detailed answer. I will try to use the new getAllCountries
The interesting part is, I am using the exact same code I used in libphonenumber plugin, and just changed it to libphonenumber_plugin because I need web platform as well. I thougth the API and the internal workings would be same. So I mean, when I supply EN in to libphonenumber, it still does not throw an exception.

I will be debugging some more. Thank you brother.

@aytunch
Copy link
Author

aytunch commented Feb 27, 2023

@natintosh I confirmed your findings above.
on iOS I use Platform.localeName which returns just EN
on Web I use ui.window.locale.countryCode which returns US
And when we give these values to getRegionInfo, I get an exception in iOS.
So if your plugin can check if the isoCode is not recognized and act accordingly without throwing that would be awesome :)
Thanks again for this awesome plugin.

@natintosh
Copy link
Owner

Yeah... I'll do that. A user also faced a similar issue with my other package. I guess it has to do with the changes I made on iOS. I had to move away from an iOS package because I haven't had any updates for like 2 years now

natintosh added a commit that referenced this issue Feb 28, 2023
natintosh added a commit that referenced this issue Feb 28, 2023
Hotfix: #15, issue with libphonenumber_plugin throwing exception whenever an invalid iso code is passed
@aytunch
Copy link
Author

aytunch commented Feb 28, 2023

@natintosh works as expected on iOS with ^0.3.1
Thank you very much

@aytunch
Copy link
Author

aytunch commented Mar 1, 2023

@natintosh what is meant here in the documentation? Are you suggesting using libphonenumber instead for iOS and Android? Or is there a typo? I need to know this before suggesting upgrading to this plugin from libphonenumber.

Also For Stable Android and iOS implementation use libphonenumber, since it was inspired by and has similar implementation with libphonenumber.

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