Comments (13)
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
OR I could create a PR.
from nkvphonepicker.
@VineetKG creating a PR would be appreciated)
from nkvphonepicker.
@NikKovIos here #59
from nkvphonepicker.
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.
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.
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.
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.
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.
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:
I would appreciate if you would try to create a PR with that 🚀
from nkvphonepicker.
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.
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.
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.
@VineetKG thx, merged
from nkvphonepicker.
Related Issues (20)
- Could not build Objective-C module 'NKVPhonePicker' HOT 4
- Appcenter.ms: Illegal character '?' NKVPhonePicker/Sources/Bundle/Countries.bundle/Images/?.png HOT 2
- NKVPhonePickerTextField.swift twice in project HOT 2
- Swift 4.2 HOT 1
- How to customize NKVFlagView ? HOT 5
- How to open NKVFlagView when user click on textField HOT 1
- Keeping getting crash in NKVPhonePickerPresenter class on textField.flagView.setFlag(with: source) HOT 2
- PlaceHolder not shown HOT 13
- Who needs a carthage support? HOT 1
- Use as independent view HOT 1
- Same country codes change conuntry flag HOT 2
- Swift Package Manager support HOT 1
- How can I use UITextFiledDelegate Methods like Should change characters with nkvtextfields HOT 1
- Plus Symbol is not centre for country code HOT 1
- RLT Support ? HOT 1
- Error: 'inset(by:)' has been renamed to 'UIEdgeInsetsInsetRect(_:_:)'
- How can validate the phone number with country code? HOT 1
- Provide a way to disable the phone formatting calls within the library; formatting functions are broken
- Dark Mode Support HOT 1
- SPM - Crash when presenting CountriesViewController
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nkvphonepicker.