GithubHelp home page GithubHelp logo

Comments (13)

VineetKG avatar VineetKG commented on June 14, 2024 1

Hi @NikKovIos ,

Firstly thanks for the nice tool :)
As an extension to the above issue could you please

  • Increase prefix length to 7 in file NKVPhonePickerTextField, let firstFourLetters = String(newString.prefix(7)). Some area codes for UK are 5 digits long.
  • and, replace localAreaCodes.json file with the attached one ?

I have added area codes for UK and conflicting countries for country code +44. Source for area codes: www.prokerala.com

localAreaCodes.json.zip

OR I could create a PR.

from nkvphonepicker.

NikKovIos avatar NikKovIos commented on June 14, 2024 1

@VineetKG creating a PR would be appreciated)

from nkvphonepicker.

VineetKG avatar VineetKG commented on June 14, 2024 1

@NikKovIos here #59

from nkvphonepicker.

NikKovIos avatar NikKovIos commented on June 14, 2024

Hello and thank you for using my lib =)
I thought about this problem all over the development and unfortunately didn't find a good solution. Maybe you can help me to concoct the algorithm about how to distinguish US and Canada ?

from nkvphonepicker.

Saikedo avatar Saikedo commented on June 14, 2024

Of course, I will be glad to help and already have a couple of ideas as to how it can be handled.

Firstly, although country codes (like +1) might not be unique to any country I believe area codes are unique so we might be able to use that to match the correct country as the textField is being filled.

Second, even before the textField gets filled beyond the country code, we can have a functionality that allows setting country priorities at least so that let`s say if I am intending to use my App mainly in the USA, then +1 code will be assigned to the USA instead of Canada. I will familiarize myself with your library by Saturday and will get back to you with a solid plan to do this.

from nkvphonepicker.

NikKovIos avatar NikKovIos commented on June 14, 2024

Waiting for your reply. Check the first point, cos i think it's already implemented.
Check the second with the property "custom phone formats". Try to set your own formats and check if the format that is taken first depends by what custom phone format is first in that array.

from nkvphonepicker.

Saikedo avatar Saikedo commented on June 14, 2024

Check the first point, cos i think it's already implemented.

Huh, it does not work for me actually, at least it did not work for few examples that I tried. For example, if you clean the textView and type 1, the country is set to Canada and since I am in U.S. and my phone area code is 818, I continue typing and now the field contains 1 818 but the country still shows up as Canada.

Check the second with the property "custom phone formats"

This does not seem to work as well for the same case. Here is what I tried

let customPhoneFormats = [
            "US" : "# ### ### ####",
            "CA" : "# ### ### ####"
        ]
phoneTextField.customPhoneFormats = customPhoneFormats

And as soon as I type 1 in the textField, Canada shows up instead of U.S. Am I doing something wrong here ?

from nkvphonepicker.

Saikedo avatar Saikedo commented on June 14, 2024

By the way, for the list of countries and their country codes, did you manually created the list or you are pulling it from somewhere. If that same source also has a list that can help us distinguish between countries with same country code based on area code, then I can implement a solution that works automatically. If not, then I already wrote a small change that at least lets you customize the priority of countries that are under the same area code.

from nkvphonepicker.

NikKovIos avatar NikKovIos commented on June 14, 2024

@Saikedo

And as soon as I type 1 in the textField, Canada shows up instead of U.S. Am I doing something wrong here ?
No, u're doing right then. =)

By the way, for the list of countries and their country codes, did you manually created the list or you are pulling it from somewhere
The list created manually, we can change it. It stores here:
2018-06-10 10 50 09

I would appreciate if you would try to create a PR with that 🚀

from nkvphonepicker.

Saikedo avatar Saikedo commented on June 14, 2024

My friend I created a new merge request for fixing the issue that we have been talking about. This update provides two ways to choose the country. One of them has to be done manually by the users of the library, but the 2nd way uses the local area codes of countries to determine the correct country. For the 2nd way, I only added the data for US and Canda but the localAreaCodes.json file can be modified to include any other countries with matching phone extensions.

Also note that although 2nd way provides an automatic way to determine the country, the 1st way is still necessary because it helps the user to set the country priority before the entire local area code is inserted.

Note: My implementation of the country picker based on area code might feel really ugly(It have like 12 nested if statements) but it is pretty straightforward code. I am new to swift and could not come up with more elegant solution. Please let me know if you can find a way to do it better.

спосибо за ваше внимание и я надеюсь что вам понравится мои дополнения.

from nkvphonepicker.

NikKovIos avatar NikKovIos commented on June 14, 2024

Great job man, very appreciate this! 😃
I gonna refractor some code in a free time, but your PR is already merged and can be fetched manually by cocoapods (git => http...)

from nkvphonepicker.

Saikedo avatar Saikedo commented on June 14, 2024

Thank you very much :)

Yes, some refactoring will certainly be great before releasing on cocoa pods.

I was honestly not happy with the samePhoneExtensionCountryPriorities variable being static but I could not think of a better way to get to this variable in Country class.

And of course, having 12 if statements nested is just horrifying but since I am new to Swift, I did not find any way to do it without nesting.

from nkvphonepicker.

NikKovIos avatar NikKovIos commented on June 14, 2024

@VineetKG thx, merged

from nkvphonepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.