nikkovios / nkvphonepicker Goto Github PK
View Code? Open in Web Editor NEWAn UITextField subclass to simplify country code's picking. Swift 5.0
Home Page: https://cocoapods.org/pods/NKVPhonePicker
License: MIT License
An UITextField subclass to simplify country code's picking. Swift 5.0
Home Page: https://cocoapods.org/pods/NKVPhonePicker
License: MIT License
It is possible to have a minimum and maximum phone number format for each country? or for all countries?
For example:
{
"name": "Bahrain",
"dial_code": "973",
"code": "BH",
"min_format": "### ######",
"max_format": "### ########"
}
This would be useful, as many countries have multi format.
@IBOutlet public weak var phonePickerDelegate: UIViewController?
你好
请问这个phonePickerDelegate如何创建?
how are you
How to create this phonePickerDelegate ?
In viewDidLoad
when I try to insatiate the NKVPhonePickerTextField
with a country it keeps crashing when trying to create the flagView
in the NKVPhonePickerPresenter
class' textField.flagView.setFlag(with: source)
.
Why does this keep happening?
let phoneTextField: NKVPhonePickerTextField = {
let textField = NKVPhonePickerTextField()
textField.autocorrectionType = .no
textField.keyboardType = .numberPad
return textField
}()
override func viewDidLoad() {
super.viewDidLoad()
phoneTextField.phonePickerDelegate = self
if let countryCode = Country.currentCountry?.countryCode, let country = Country.country(for: NKVSource(countryCode: countryCode)) {
let source = NKVSource(country: country)
phoneTextField.flagView.setFlag(with: source)
phoneTextField.setFlag(source: source)
phoneTextField.setFlag(source: source)
phoneTextField.country = country
}
}
crashes in this class
class NKVPhonePickerPresenter {
/// Method for set flag with countryCode.
public func setFlag(source: NKVSource) {
textField.flagView.setFlag(with: source) // ***IT CRASHES ON THIS LINE***
}
}
CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler
cd /Users/vsts/agent/2.140.2/work/1/s/Pods
export DEVELOPER_DIR=/Applications/Xcode_9.4.1.app/Contents/Developer
export PATH="/Applications/Xcode_9.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode_9.4.1.app/Contents/Developer/usr/bin:/Library/Frameworks/Mono.framework/Versions/4/bin:/usr/local/bin:/usr/local/sbin:/Users/vsts/bin:/Users/vsts/.yarn/bin:/usr/local/go/bin:/Users/vsts/Library/Android/sdk/tools:/Users/vsts/Library/Android/sdk/platform-tools:/Users/vsts/Library/Android/sdk/ndk-bundle:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/Users/vsts/.azcopy"
export SDKROOT=/Applications/Xcode_9.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk
>/Applications/Xcode_9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -incremental -module-name NKVPhonePicker -O -whole-module-optimization -D COCOAPODS -suppress-warnings -sdk /Applications/Xcode_9.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk -target armv7-apple-ios9.0 -g -module-cache-path /Users/vsts/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -Xfrontend -serialize-debugging-options -embed-bitcode -swift-version 3 -I /Users/vsts/Library/Developer/Xcode/DerivedData/Robomed-hkguzfozedxpeactgxnakujerabq/Build/Intermediates.noindex/ArchiveIntermediates/Robomed/BuildProductsPath/Release-iphoneos/NKVPhonePicker -F /Users/vsts/Library/Developer/Xcode/DerivedData/Robomed-hkguzfozedxpeactgxnakujerabq/Build/Intermediates.noindex/ArchiveIntermediates/Robomed/BuildProductsPath/Release-iphoneos/NKVPhonePicker -c -num-threads 4 /Users/vsts/agent/2.140.2/work/1/s/Pods/NKVPhonePicker/Sources/Main/CountriesViewController.swift /Users/v...
:0: error: filename "NKVPhonePickerTextField.swift" used twice:
'/Users/vsts/agent/2.140.2/work/1/s/Pods/NKVPhonePicker/Sources/Main/NKVPhonePickerTextField.swift' and
'/Users/vsts/agent/2.140.2/work/1/s/Pods/NKVPhonePicker/Sources/Views/NKVPhonePickerTextField.swift'
:0: note: filenames are used to distinguish private declarations with the same name
Command /Applications/Xcode_9.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
there double files NKVPhonePickerTextField in project.
'/Users/vsts/agent/2.140.2/work/1/s/Pods/NKVPhonePicker/Sources/Main/NKVPhonePickerTextField.swift'
'/Users/vsts/agent/2.140.2/work/1/s/Pods/NKVPhonePicker/Sources/Views/NKVPhonePickerTextField.swift'
If edit when number is already exists the flag not changes.
NKVPhonePicker Version:
iOS Version(s):
Swift Version:
Device or Simulator:
Did you check an example:
We have 2 patterns:
+55 (XX) XXXXX-XXXX
and
+55 (XX) XXXX-XXXX
country code
state code (2 digits)
4 or 5 digits, then 4 digits
It depends on which state the number is
phonePickerDelegate should assign to uiviewcontroller. Is there any way?
Is it possible to get the dial code from the phone number?
The following code will give me the phone number along with the dial code:
txtPhoneNumber.phoneNumber
Is there any way to get the phone number without dial code, and get dial code without phone number?
When I start the app, I set the default country for the NKVPhonePickerTextField using the Locale.regionCode, to display the equivalent code and flag.
If the user changes the default set country by deleting the default code and replacing it with another code, the country object associated with the NKVPhonePickerTextField doesn't get updated and when navigating to the countries view controller, the old country (the default one) is still set by a checkmark.
Hello, there's a problem with the country selection. If i select United States, it shows me the Canada Flag. The selection for UK also shows wrong flag.
NKVPhonePicker Version:
iOS Version(s):
Swift Version:
Device or Simulator:
Did you check an example:
I believe there is no way to set the phonePickerDelegate as it's not an option while using the picker programmatically. Or I haven't figured out the way.
Some countries such as U.S. and Canada both start with code +1 and it seems like for this particular example, library defaults to Canada and shows the Canadian flag. Is there a way to modify this behaviour?
Hello, is it possible to get selected Country Code like "RU", "GB", etc?
I tried to make an extension and return
return self.flagView.currentPresentingCountry.countryCode
but im getting error 'flagview is inaccessible due to internal protection level'
Thanks
App stucks on launch screen without errors.
It is working progrmatically but not with storyboard
Hello, first of all thank you for such an awesome library.
Just installed it via cocoapods as instructed in your README.md file. Unfortunately when implementing it, the countries view controller doesn't get presented. When comparing files downloaded via cocoapods with the files included in the provided example, they're not the same.
Thanks!
I am developing a softphone, I have my own numpad. I could not set pressed button value to NKVPhonePickerTextField
. It's appending first digit only.
func buttonPressed(digit: String) {
var val = txtDialedNumber.text
val?.append(digit)
txtDialedNumber.text = val
// i tried this -> txtDialedNumber.text.append(digit)
}
there is know way to force country Not to change
by click on the flag or remove the code text
when delete old mobile it may not delete country code and not change the country flag
NKVPhonePicker Version:
iOS Version(s):
Swift Version:
Device or Simulator:
Did you check an example:
Hi!
If I set customPhoneFormats as "### ## ### ## ##" and start typing phone number, the resulting phone number looks as follows "+374 28123456678901", but when I delete digits up to country code "+374" and try to type phone number again - format applies correctly.
NKVPhonePicker Version: 2.1.1
iOS Version(s): iOS 15.5
Swift Version: 5.5
Device or Simulator: Both
Did you check an example:
Could not find a storyboard named 'CountriesViewController' in bundle NSBundle
Tapping on flag icon should not crash.
NKVPhonePicker Version:2.1.0
iOS Version(s):14.0
Swift Version:5.3
Device or Simulator:both and no all models
Did you check an example: yes
Let's say you set (either on device or simulator) the flag for chile (using the figer taps, not programatically) and then you type in your number. It's perfect. Now let's say you go back and return to this screen, only this time the request provides you a phone number so you call the preFillText function which calls the setcode, set flag functions and sets the text property. Within both the setflag and setcode functions there are calls for formatting the phone number in accordance to your custom formats (which is not the case here) or to the current country based on the nkv source you pass in using the country code. The sources, the country codes, numbers and all of them are correct but upon "formatting" the number the phone number gets changed and is being added the last 3 chars again in the end of the number. So if the phone number is this (for chile for example): 56 9 2522 5421 then the prefilltext function will mess up with this number and in the end you will see displayed in the phone field this: 56 9 2522 5421421.
I managed to overcome this by setting the current country initially to false, setting the text property of the field as is from the response and by manually setting the phonePicker.flagView.flagButton.setImage using the UIImage constructor with the bundle. What would be nice is if we could get acces to the NKVSourcesHelper struct so we can use the static functions from there but i got the job done.
I expected the phone number to not get any other chars added to it, cause that's not ok at all.
Please provide a boolean so we can set it to false and if that's false then by calling preFillText it won't call the enablePhoneFormat within it and also it won't call the by callin the setFlag function it won't call the textField.presenter.enablePhoneFormat function within it.
Please provide access so we can at least call the NKVSourcesHelper struct and just get the flag(for: source) result.
If you need a Carthage for this framework, write here please.
NKVPhonePicker Version: 2.0.1
iOS Version(s): 11
Swift Version: 4.1
Device or Simulator: Simulator
Did you check an example:
Try to search country from search text field
Select country
Selected search Country did not reflect.
also, App crash when Dismiss Search
Selected search country should appear in the text field
The app should not crash on dismiss
Crash Logs:
2018-06-13 16:19:54.450526+0530 PocketRehab[2300:25819] [Common] _BSMachError: port 1e53b; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2018-06-13 16:19:54.506719+0530 PocketRehab[2300:25819] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modal view controller on itself. Presenting controller is <UISearchController: 0x7feea6635a00>.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000112f941e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000112625031 objc_exception_throw + 48
2 UIKit 0x0000000110021a95 __78-[UIViewController _presentViewController:withAnimationController:completion:]_block_invoke + 0
3 UIKit 0x00000001100242c6 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 99
4 UIKit 0x0000000110024958 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
5 UIKit 0x000000011002422c -[UIViewController _presentViewController:animated:completion:] + 169
6 UIKit 0x0000000110024570 -[UIViewController presentViewController:animated:completion:] + 154
7 UIKit 0x0000000110c25bd9 __51-[UISearchController _performAutomaticPresentation]_block_invoke + 330
8 UIKit 0x0000000110bc7a29 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 294
9 UIKit 0x0000000110bc36d5 -[_UIViewControllerTransitionContext _runAlongsideCompletions] + 132
10 UIKit 0x0000000110bc33c4 -[_UIViewControllerTransitionContext completeTransition:] + 118
11 UIKit 0x000000010fe754b3 _runAfterCACommitDeferredBlocks + 318
12 UIKit 0x000000010fe6471e _cleanUpAfterCAFlushAndRunDeferredBlocks + 388
13 UIKit 0x000000010fe92ea5 _afterCACommitHandler + 137
14 CoreFoundation 0x0000000112f36607 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
15 CoreFoundation 0x0000000112f3655e __CFRunLoopDoObservers + 430
16 CoreFoundation 0x0000000112f1ab81 __CFRunLoopRun + 1537
17 CoreFoundation 0x0000000112f1a30b CFRunLoopRunSpecific + 635
18 GraphicsServices 0x0000000119403a73 GSEventRunModal + 62
19 UIKit 0x000000010fe6a057 UIApplicationMain + 159
20 PocketRehab 0x000000010f157687 main + 55
21 libdyld.dylib 0x0000000114bc3955 start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
following link helps me to resolved crash
https://stackoverflow.com/questions/46917918/ios-uisearchcontroller-crash-application-tried-to-present-modal-view-controller?rq=1&utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
When I start to tap search bar and then dismiss the keyboard it make tableview offset bug
Could it be independent view as "Flag + Country Code"?
Thanks for this great project
NKVPhonePicker Version:
iOS Version(s): 12.1
Swift Version: 4.2
Device or Simulator:
Did you check an example:
don't work with 4.2
there is lost for compiler error
if you try it will be very quick if you have fixed it thanks
also it crash when I try to fixed all swift 4.2 issue so please check that too
NKVPhonePicker Version:
iOS Version(s):
Swift Version:
Device or Simulator:
Did you check an example:
I'm trying to pre fill the text field with the current phone number of the user, but the flag is not getting updated and also it's taking the code of US "+1" when the number is "569812312322" that is a Chilean number.
I'm using textfield.text = "569812312322" to pre fill the text field.
Flag not getting updated and also wrong country code.
Set the flag to Chile and keep the correct code "56".
Placeholder is not shown even if set it programatically or from storyboard
Placeholder should shown in text feild
NKVPhonePicker Version: Not sure, because there is not version in pod file
iOS Version(s): 12.0
Swift Version: 4.0
Device or Simulator: iPhone 11
Did you check an example:
Error: 'inset(by:)' has been renamed to 'UIEdgeInsetsInsetRect(::)'
pods/NKVPhonePicker/NKVPhonePickerTextField.swift line 267
functions starts
override open func textRect(forBounds bounds: CGRect) -> CGRect {
How to fix this problem?
NKVPhonePicker Version: NA
iOS Version(s): 12.0
Swift Version: 4.2
Device or Simulator: Both
Did you check an example: Yes
When user click on textField, keyboard was showing but I want to show flagView using MKFlagView
I want to show flagView using MKFlagView when click on textFIeld and update textFIeld text with selected country name.
NKVPhonePicker Version:
iOS Version(s):
Swift Version:
Device or Simulator:
Did you check an example:
NKVPhonePicker Version:
iOS Version(s):
Swift Version:
Device or Simulator:
Did you check an example:
Trying to make a build of app on the appcenter.ms got that error:
Start uploading file 'build/Robomed.xcarchive/Products/Applications/Robomed.app/Frameworks/NKVPhonePicker.framework/Countries.bundle/Images/?.png' to server, chunk '1'.
Chunk '1' attempt '2' of file 'build/Robomed.xcarchive/Products/Applications/Robomed.app/Frameworks/NKVPhonePicker.framework/Countries.bundle/Images/?.png' fail to send request to server. Error: Microsoft.VisualStudio.Services.WebApi.VssServiceResponseException: Wildcards are not allowed. ---> Microsoft.TeamFoundation.InvalidPathException: Wildcards are not allowed.
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.d__16.MoveNext().
##[error]File upload failed even after retry.
Deleted the NKVPhonePicker from the project and build success.
So the problem is files with '?' in name, which is not supported by Microsoft file systems 👎
Success build without deleting NKVPhonePicker from the project.
Hope you find here Screen Short : https://prnt.sc/pxwunv
I have textfield with class of NKVPhonePicker and position is (20, 50, 335, 50), I set up Initial country code as IN ...Here is my code
/*
countryTF?.favoriteCountriesLocaleIdentifiers = ["RU", "ER", "JM"]
countryTF?.rightToLeftOrientation = false
countryTF?.shouldScrollToSelectedCountry = false
countryTF?.flagSize = CGSize(width: 30, height: 50)
countryTF?.enablePlusPrefix = true
let country = Country.country(for: NKVSource(countryCode: "IN"))
countryTF?.country = country
countryTF?.customPhoneFormats = ["IN" : "## #### ### ###"]
*/
If + will centre to Country code it looks good . May be it will helpful to all
Could not build Objective-C module 'NKVPhonePicker'
after updated pods for xcode 9 and I'm getting the error below for NKVPhonePicker.
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
When i set phone no programmatically it not setting up flag correctly, ex i am setting india no it showing us flag
bottomTextField.text="918122100747"
Is it compatible with obj-c ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.